private Task <CopyObjectResult> PutInternalAsync( string name, S3ObjectLocation sourceLocation, IReadOnlyDictionary <string, string> metadata = null) { var request = new CopyObjectRequest( host: client.Host, source: sourceLocation, target: new S3ObjectLocation(bucketName, name) ); SetHeaders(request, metadata); return(client.CopyObjectAsync(request)); }
public async Task <CopyObjectResult> PutAsync( string destinationKey, S3ObjectLocation sourceLocation, IReadOnlyDictionary <string, string>?metadata = null) { if (destinationKey is null) { throw new ArgumentNullException(nameof(destinationKey)); } int retryCount = 0; Exception lastException; do { if (retryCount > 0) { await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); } var request = new CopyObjectRequest( host: client.Host, source: sourceLocation, target: new S3ObjectLocation(bucketName, destinationKey) ); if (metadata != null) { request.MetadataDirective = MetadataDirectiveValue.Replace; SetHeaders(request, metadata); } try { return(await client.CopyObjectAsync(request).ConfigureAwait(false)); } catch (S3Exception ex) when(ex.IsTransient) { lastException = ex; } retryCount++; }while (retryPolicy.ShouldRetry(retryCount)); throw new S3Exception($"Error copying '{sourceLocation}' to '{destinationKey}'", lastException); }