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

Get a misleading error message when uploading file to data endpoint without setting a file name #220

Open
lil131 opened this issue Sep 30, 2021 · 3 comments
Labels
good first issue Good for newcomers

Comments

@lil131
Copy link
Contributor

lil131 commented Sep 30, 2021

If uploading a file to the /namespaces/{ns}/data endpoint, and the file name is "" or not set, the request will fail with a misleading error message:

{
"error": "FF10218: Error reading multi-part form input: EOF"
}

@lil131
Copy link
Contributor Author

lil131 commented Sep 30, 2021

for {
part, err := mpr.NextPart()
if err != nil {
return nil, i18n.WrapError(ctx, err, i18n.MsgMultiPartFormReadError)
}
if part.FileName() == "" {
value, _ := ioutil.ReadAll(part)
formParams[part.FormName()] = string(value)
} else {
l.Debugf("Processing multi-part upload. Field='%s' Filename='%s'", part.FormName(), part.FileName())
mp := &fftypes.Multipart{
Data: part,
Filename: part.FileName(),
Mimetype: part.Header.Get("Content-Disposition"),
}
return &multipartState{
mpr: mpr,
formParams: formParams,
part: mp,
close: func() { _ = part.Close() },
}, nil
}
}

@awrichar awrichar added the good first issue Good for newcomers label Aug 9, 2022
@AryanSharma9917
Copy link

AryanSharma9917 commented May 6, 2023

Heyy @lil131 , @awrichar , can I work on this issue?

@AryanSharma9917
Copy link

AryanSharma9917 commented May 6, 2023

Here's what I can perform

func uploadHandler(w http.ResponseWriter, r *http.Request) {

// Check if the file name is empty or not set
file, header, err := r.FormFile("file")
if err != nil {

	http.Error(w, err.Error(), http.StatusInternalServerError)
	return
}
defer file.Close()
if header.Filename == "" {
	http.Error(w, "Error: File name is empty or not set", http.StatusBadRequest)
	return
}

fmt.Fprintf(w, "File uploaded successfully!")

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants