Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor createMultipartRequestBody to support custom content types a… #204

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

ShocOne
Copy link
Contributor

@ShocOne ShocOne commented Jun 5, 2024

…nd headers

Change

Thank you for your contribution !
Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context.
List any dependencies that are required for this change.

Type of Change

Please DELETE options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update (Wiki)
  • Refactor (refactoring code, removing code, changing code structure)

Checklist

  • I'm sure there are no other open Pull Requests for the same update/change
  • My corresponding pipelines / checks run clean and green without any errors or warnings
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (readme)
  • I did format my code

@ShocOne ShocOne merged commit ec4a9dd into main Jun 5, 2024
2 of 7 checks passed
return nil, "", err
}
if err := writer.Close(); err != nil {
log.Error("Failed to close writer", zap.Error(err))

Check warning

Code scanning / Golang security checks by gosec

Errors unhandled. Warning

Errors unhandled.
}
// addFilePart adds a file part to the multipart writer with the provided field name and file path.
func addFilePart(writer *multipart.Writer, fieldName, filePath string, contentTypes map[string]string, headersMap map[string]http.Header, log logger.Logger) error {
file, err := os.Open(filePath)

Check failure

Code scanning / Golang security checks by gosec

Potential file inclusion via variable Error

Potential file inclusion via variable
return err
}
if _, err := fieldWriter.Write([]byte(val)); err != nil {
log.Error("Failed to write form field", zap.String("key", key), zap.Error(err))

Check warning

Code scanning / Golang security checks by gosec

Errors unhandled. Warning

Errors unhandled.
func addFormField(writer *multipart.Writer, key, val string, log logger.Logger) error {
fieldWriter, err := writer.CreatePart(FormDataHeader(key, "text/plain"))
if err != nil {
log.Error("Failed to create form field", zap.String("key", key), zap.Error(err))

Check warning

Code scanning / Golang security checks by gosec

Errors unhandled. Warning

Errors unhandled.

progressLogger := logUploadProgress(fileSize.Size(), log)
if err := chunkFileUpload(file, part, log, progressLogger); err != nil {
log.Error("Failed to copy file content", zap.String("filePath", filePath), zap.Error(err))

Check warning

Code scanning / Golang security checks by gosec

Errors unhandled. Warning

Errors unhandled.
return body, writer.FormDataContentType(), nil
fileSize, err := file.Stat()
if err != nil {
log.Error("Failed to get file info", zap.String("filePath", filePath), zap.Error(err))

Check warning

Code scanning / Golang security checks by gosec

Errors unhandled. Warning

Errors unhandled.
if err != nil {
log.Error("Failed to close writer", zap.Error(err))
return nil, "", err
log.Error("Failed to create form file part", zap.String("fieldName", fieldName), zap.Error(err))

Check warning

Code scanning / Golang security checks by gosec

Errors unhandled. Warning

Errors unhandled.
func addFilePart(writer *multipart.Writer, fieldName, filePath string, contentTypes map[string]string, headersMap map[string]http.Header, log logger.Logger) error {
file, err := os.Open(filePath)
if err != nil {
log.Error("Failed to open file", zap.String("filePath", filePath), zap.Error(err))

Check warning

Code scanning / Golang security checks by gosec

Errors unhandled. Warning

Errors unhandled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant