diff --git a/httpclient/multipartrequest.go b/httpclient/multipartrequest.go index 484d853..4a89726 100644 --- a/httpclient/multipartrequest.go +++ b/httpclient/multipartrequest.go @@ -324,8 +324,9 @@ func setFormDataPartHeader(fieldname, filename, contentType string, customHeader return header } -// chunkFileUpload reads the file in chunks and writes it to the writer. +// chunkFileUpload reads the file upload into chunks and writes it to the writer. // This function reads the file in chunks and writes it to the provided writer, allowing for progress logging during the upload. +// chunk size is set to 5124 KB (5 MB) by default. // Parameters: // - file: The file to be uploaded. @@ -338,10 +339,11 @@ func setFormDataPartHeader(fieldname, filename, contentType string, customHeader // - error: An error object indicating failure during the file upload. This could be due to issues such as file reading errors // or writer errors. func chunkFileUpload(file *os.File, writer io.Writer, log logger.Logger, updateProgress func(int64)) error { - const chunkSize = 2024 * 1024 // 2024 KB in bytes, adjust this as needed + const chunkSize = 5124 * 1024 // 5124 KB in bytes (5 MB) buffer := make([]byte, chunkSize) totalWritten := int64(0) chunkWritten := int64(0) + fileName := filepath.Base(file.Name()) for { n, err := file.Read(buffer) @@ -361,16 +363,21 @@ func chunkFileUpload(file *os.File, writer io.Writer, log logger.Logger, updateP chunkWritten += int64(written) updateProgress(int64(written)) - // Log progress for every 1MB chunk written if chunkWritten >= chunkSize { - log.Debug("Chunk written", zap.Int64("bytes_written", chunkWritten), zap.Int64("total_written", totalWritten)) + log.Debug("File Upload Chunk Sent", + zap.String("file_name", fileName), + zap.Int64("kb_sent", chunkWritten/1024), + zap.Int64("total_kb_sent", totalWritten/1024)) chunkWritten = 0 } } // Log any remaining bytes that were written but didn't reach the log threshold if chunkWritten > 0 { - log.Debug("Final chunk written", zap.Int64("bytes_written", chunkWritten), zap.Int64("total_written", totalWritten)) + log.Debug("Final Upload Chunk Sent", + zap.String("file_name", fileName), + zap.Int64("kb_sent", chunkWritten/1024), + zap.Int64("total_kb_sent", totalWritten/1024)) } return nil