diff --git a/lib/src/client.dart b/lib/src/client.dart index 7e51787..a7c86b2 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -714,4 +714,79 @@ class Client with AuthMixin, HttpMixin implements ClientApi { return await Future.wait(deletes); } + + /// initiateMultipartUpload from oss + @override + Future> initiateMultipartUpload( + String fileKey, { + String? bucketName, + CancelToken? cancelToken, + }) async { + final String bucket = bucketName ?? this.bucketName; + final Auth auth = await getAuth(); + + final String url = "https://$bucket.$endpoint/$fileKey?uploads"; + final HttpRequest request = HttpRequest.post(url); + auth.sign(request, bucket, "$fileKey?uploads"); + + return _dio.post( + request.url, + cancelToken: cancelToken, + options: Options(headers: request.headers), + ); + } + + /// uploadPart from oss + @override + Future> uploadPart( + String fileKey, + List partData, + int partNumber, + String uploadId, { + String? bucketName, + CancelToken? cancelToken, + }) async { + final String bucket = bucketName ?? this.bucketName; + final Auth auth = await getAuth(); + + final String url = + "https://$bucket.$endpoint/$fileKey?partNumber=$partNumber&uploadId=$uploadId"; + final HttpRequest request = HttpRequest.put(url, headers: { + 'content-type': 'application/octet-stream', + }); + auth.sign(request, bucket, "$fileKey?partNumber=$partNumber&uploadId=$uploadId"); + + return _dio.put( + request.url, + data: partData, + cancelToken: cancelToken, + options: Options(headers: request.headers), + ); + } + + /// completeMultipartUpload from oss + @override + Future> completeMultipartUpload( + String fileKey, + String uploadId, + String data, { + String? bucketName, + CancelToken? cancelToken, + }) async { + final String bucket = bucketName ?? this.bucketName; + final Auth auth = await getAuth(); + + final String url = "https://$bucket.$endpoint/$fileKey?uploadId=$uploadId"; + final HttpRequest request = HttpRequest.post(url, headers: { + 'content-type': 'application/xml', + }); + auth.sign(request, bucket, "$fileKey?uploadId=$uploadId"); + + return _dio.post( + request.url, + data: data, + cancelToken: cancelToken, + options: Options(headers: request.headers), + ); + } } diff --git a/lib/src/client_api.dart b/lib/src/client_api.dart index 9cc2c95..dba3faa 100644 --- a/lib/src/client_api.dart +++ b/lib/src/client_api.dart @@ -156,4 +156,27 @@ abstract class ClientApi { String? bucketName, CancelToken? cancelToken, }); + + Future> initiateMultipartUpload( + String fileKey, { + String? bucketName, + CancelToken? cancelToken, + }); + + Future> uploadPart( + String fileKey, + List partData, + int partNumber, + String uploadId, { + String? bucketName, + CancelToken? cancelToken, + }); + + Future> completeMultipartUpload( + String fileKey, + String uploadId, + String data, { + String? bucketName, + CancelToken? cancelToken, + }); }