Skip to content

Commit 021768c

Browse files
committed
Add configurable chunked encoding for S3 uploads
Added support for a useChunkEncoding parameter to control whether chunked encoding is used when uploading to S3. The setting is parsed during initialization and applied to PutObjectRequest, allowing for more flexible S3 compatibility.
1 parent 81ce5c0 commit 021768c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Octockup.Server/Modules/S3BackupStorage.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class S3BackupStorage(ILogger<S3BackupStorage> _logger) : IBackupStorage
2020
private string? _path;
2121
private string? _bucket;
2222
private AmazonS3Client? _s3;
23+
private bool _useChunkEncoding = true;
2324
private bool _validateChecksums = false;
2425
private ICollection<string>? _ignoredPaths;
2526

@@ -56,6 +57,13 @@ public void SetParameters(IReadOnlyDictionary<string, string> parameters)
5657
string accessKey = parameters["accessKey"];
5758
string secretKey = parameters["secretKey"];
5859

60+
bool hasChunkEncodingParam = parameters.TryGetValue("useChunkEncoding", out var chunkEncodingStr);
61+
if (hasChunkEncodingParam)
62+
{
63+
bool parsed = bool.TryParse(chunkEncodingStr, out var chunkEncodingBool);
64+
_useChunkEncoding = parsed && chunkEncodingBool;
65+
}
66+
5967
_s3 = new AmazonS3Client(accessKey, secretKey, config);
6068
}
6169

@@ -415,7 +423,7 @@ public Task UploadAsync(string path, Stream data, CancellationToken cancellation
415423
Key = key,
416424
InputStream = data,
417425
BucketName = _bucket,
418-
UseChunkEncoding = false,
426+
UseChunkEncoding = _useChunkEncoding,
419427
ContentType = MediaTypeNames.Application.Octet,
420428
};
421429

0 commit comments

Comments
 (0)