firefly icon indicating copy to clipboard operation
firefly copied to clipboard

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

Open lil131 opened this issue 4 years ago • 3 comments

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 avatar Sep 30 '21 15:09 lil131

https://github.com/hyperledger/firefly/blob/e9b7b74be7a0bd0719313b8dc35f265c84100d28/internal/apiserver/server.go#L130-L152

lil131 avatar Sep 30 '21 15:09 lil131

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

AryanSharma9917 avatar May 06 '23 19:05 AryanSharma9917

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!")

}

AryanSharma9917 avatar May 06 '23 19:05 AryanSharma9917