Skip to content

Commit ab44edb

Browse files
authored
Merge pull request #232 from deploymenttheory/dev-multipartfix
Refactor chunk size for file upload in multipart request to 8MB for i…
2 parents 2d0fb0f + 7f52fa0 commit ab44edb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

httpclient/multipartrequestwithretry.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ func setFormDataPartHeader(fieldname, filename, contentType string, customHeader
294294

295295
// chunkFileUpload reads the file upload into chunks and writes it to the writer.
296296
// This function reads the file in chunks and writes it to the provided writer, allowing for progress logging during the upload.
297-
// chunk size is set to 65536 KB (64 MB) by default.
297+
// chunk size is set to 8192 KB (8 MB) by default. This is a common chunk size used for file uploads to cloud storage services.
298+
299+
// Azure Blob Storage has a minimum chunk size of 4 MB and a maximum of 100 MB for block blobs.
300+
// GCP Cloud Storage has a minimum chunk size of 256 KB and a maximum of 5 GB.
301+
// AWS S3 has a minimum chunk size of 5 MB and a maximum of 5 GB.
298302

299303
// Parameters:
300304
// - file: The file to be uploaded.
@@ -306,10 +310,8 @@ func setFormDataPartHeader(fieldname, filename, contentType string, customHeader
306310
// Returns:
307311
// - error: An error object indicating failure during the file upload. This could be due to issues such as file reading errors
308312
// or writer errors.
309-
//
310-
// chunkFileUpload reads the file upload into chunks and writes it to the writer.
311313
func chunkFileUpload(file *os.File, writer io.Writer, log logger.Logger, updateProgress func(int64), uploadState *UploadState) error {
312-
const chunkSize = 65536 * 1024 // 65536 * 1024 bytes (64 MB)
314+
const chunkSize = 8 * 1024 * 1024 // 8 * 1024 * 1024 bytes (8 MB)
313315
buffer := make([]byte, chunkSize)
314316
totalWritten := int64(0)
315317
chunkWritten := int64(0)

0 commit comments

Comments
 (0)