Implementation
@override
Future<bool> upload() async {
/*
This function uploads the contents contained in the config to the cloud.
It returns true if the upload was successful.
*/
AWSSigV4Signer client = AWSSigV4Signer(
region: config.credentailsConfig.region,
accessKey: config.credentailsConfig.accessKey,
secretKey: config.credentailsConfig.secretKey,
hostEndpoint: config.credentailsConfig.host);
final datetime = Utils.generateDatetime(); //The current date
final authorizationHeader = client.buildAuthorizationHeader(
'PUT',
'/${config.url}',
{},
Utils.trimString(datetime),
requestPayload: config.content!,
);
var header = client.headers;
header['Authorization'] = authorizationHeader;
BaseOptions options = BaseOptions(method: 'PUT', headers: header);
final dio = Dio(options);
final Completer<bool> uploadCompleter = Completer();
//Upload the object
await dio.put(
'https://${config.credentailsConfig.host}/${config.url}',
data: config.content,
onSendProgress: (count, total) {
print('$count/$total');
_uploadProgress.add([count, total]);
},
).then(
(value) {
onUploadComplete?.call(value, value.headers['x-amz-version-id']![0]);
uploadCompleter.complete(true);
},
onError: (error) {
uploadCompleter.complete(false);
},
);
return uploadCompleter.future;
}