diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart b/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart index c0e62f17c7..ad86fdf5aa 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart @@ -214,16 +214,16 @@ class StorageS3Service { required StoragePath path, required StorageGetPropertiesOptions options, }) async { - final fullPath = await _pathResolver.resolvePath(path: path); + final resolvedPath = await _pathResolver.resolvePath(path: path); return S3GetPropertiesResult( storageItem: S3Item.fromHeadObjectOutput( await headObject( s3client: _defaultS3Client, bucket: _s3PluginConfig.bucket, - key: fullPath, + key: resolvedPath, ), - path: fullPath, + path: resolvedPath, ), ); } @@ -255,18 +255,12 @@ class StorageS3Service { ); } - final fullPath = await _pathResolver.resolvePath(path: path); - var keyToGetUrl = fullPath; - if (!keyToGetUrl.startsWith('/')) { - keyToGetUrl = '/$keyToGetUrl'; - } - + var resolvedPath = await _pathResolver.resolvePath(path: path); var host = '${_s3PluginConfig.bucket}.${_getS3EndpointHost(region: _s3PluginConfig.region)}'; - if (_defaultS3ClientConfig.usePathStyle) { host = host.replaceFirst('${_s3PluginConfig.bucket}.', ''); - keyToGetUrl = '/${_s3PluginConfig.bucket}$keyToGetUrl'; + resolvedPath = '/${_s3PluginConfig.bucket}/$resolvedPath'; } else if (s3PluginOptions.useAccelerateEndpoint) { // https: //docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration-getting-started.html host = host @@ -277,7 +271,7 @@ class StorageS3Service { final urlRequest = AWSHttpRequest.raw( method: AWSHttpMethod.get, host: host, - path: keyToGetUrl, + path: resolvedPath, ); return S3GetUrlResult( diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/task/s3_upload_task.dart b/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/task/s3_upload_task.dart index 13681cedc8..dc0fac48bd 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/task/s3_upload_task.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/task/s3_upload_task.dart @@ -150,7 +150,7 @@ class S3UploadTask { bool _isMultipartUpload = false; late StorageTransferState _state; - late final String _resolvedKey; + late final String _resolvedPath; // fields used to manage the single upload process smithy.SmithyOperation? _putObjectOperation; @@ -200,7 +200,7 @@ class S3UploadTask { } try { - await _setResolvedKey(); + await _setResolvedPath(); } on Exception catch (error, stackTrace) { _completeUploadWithError(error, stackTrace); return; @@ -307,8 +307,8 @@ class S3UploadTask { } } - Future _setResolvedKey() async { - _resolvedKey = await _pathResolver.resolvePath(path: _path); + Future _setResolvedPath() async { + _resolvedPath = await _pathResolver.resolvePath(path: _path); } Future _startPutObject(S3DataPayload body) async { @@ -320,7 +320,7 @@ class S3UploadTask { ..bucket = _bucket ..body = body ..contentType = body.contentType ?? fallbackContentType - ..key = _resolvedKey + ..key = _resolvedPath ..metadata.addAll(_metadata); }); @@ -345,11 +345,11 @@ class S3UploadTask { await StorageS3Service.headObject( s3client: _s3Client, bucket: _bucket, - key: _resolvedKey, + key: _resolvedPath, ), - path: _resolvedKey, + path: _resolvedPath, ) - : S3Item(path: _resolvedKey), + : S3Item(path: _resolvedPath), ); _state = StorageTransferState.success; @@ -454,11 +454,11 @@ class S3UploadTask { await StorageS3Service.headObject( s3client: _s3Client, bucket: _bucket, - key: _resolvedKey, + key: _resolvedPath, ), - path: _resolvedKey, + path: _resolvedPath, ) - : S3Item(path: _resolvedKey), + : S3Item(path: _resolvedPath), ); _state = StorageTransferState.success; _emitTransferProgress(); @@ -474,7 +474,7 @@ class S3UploadTask { builder ..bucket = _bucket ..contentType = contentType ?? fallbackContentType - ..key = _resolvedKey + ..key = _resolvedPath ..metadata.addAll(_metadata); }); @@ -491,7 +491,7 @@ class S3UploadTask { await _transferDatabase.insertTransferRecord( TransferRecord( uploadId: uploadId, - objectKey: _resolvedKey, + objectKey: _resolvedPath, createdAt: DateTime.now(), ), ); @@ -518,7 +518,7 @@ class S3UploadTask { final request = s3.CompleteMultipartUploadRequest.build((builder) { builder ..bucket = _bucket - ..key = _resolvedKey + ..key = _resolvedPath ..uploadId = _multipartUploadId ..multipartUpload = s3.CompletedMultipartUpload( parts: (_completedSubtasks @@ -638,7 +638,7 @@ class S3UploadTask { builder ..bucket = _bucket ..body = partBody - ..key = _resolvedKey + ..key = _resolvedPath ..partNumber = partNumber ..uploadId = _multipartUploadId; }); @@ -729,7 +729,7 @@ class S3UploadTask { final request = s3.AbortMultipartUploadRequest.build((builder) { builder ..bucket = _bucket - ..key = _resolvedKey + ..key = _resolvedPath ..uploadId = _multipartUploadId; });