putObject method
Future<Response>
putObject(
- List<
int> fileData, - String fileKey, {
- CancelToken? cancelToken,
- PutRequestOption? option,
upload object(file) to oss server
fileData
is the binary data that will send to oss server
bucketName is optional, we use the default bucketName as we defined in Client
Implementation
@override
Future<Response<dynamic>> putObject(
List<int> fileData,
String fileKey, {
CancelToken? cancelToken,
PutRequestOption? option,
}) async {
final String bucket = option?.bucketName ?? bucketName;
final Auth auth = await getAuth();
final MultipartFile multipartFile = MultipartFile.fromBytes(
fileData,
filename: fileKey,
);
final Callback? callback = option?.callback;
final Map<String, dynamic> internalHeaders = {
'content-type': contentType(fileKey),
'content-length': multipartFile.length,
'x-oss-forbid-overwrite': option.forbidOverride,
'x-oss-object-acl': option.acl,
'x-oss-storage-class': option.storage,
};
final Map<String, dynamic> externalHeaders = option?.headers ?? {};
final Map<String, dynamic> headers = {
...internalHeaders,
if (callback != null) ...callback.toHeaders(),
...externalHeaders,
};
final String url = "https://$bucket.$endpoint/$fileKey";
final HttpRequest request = HttpRequest.put(url, headers: headers);
auth.sign(request, bucket, fileKey);
return _dio.put(
request.url,
data: multipartFile.chunk(),
cancelToken: cancelToken,
options: Options(headers: request.headers),
onSendProgress: option?.onSendProgress,
onReceiveProgress: option?.onReceiveProgress,
);
}