menu

arrow_back How do I get the photo from a POST request that came to the server in golang?

by
1 vote
The backend is in golang. A multipartform-data POST request with an image is sent to the server. I need to get this image and save it on the server. Can you tell me how to do it? Preferably with code example.)

1 comment

Is it a problem to get a field with a picture, or do not know how to create an application?

1 Answer

by
0 votes
You take this picture out of*http.Request , by the key (in this case "file"), then create a file and copy there from the form
file, fileHeader, err := r.FormFile("file")
if err != nil {
log.Fatal(err)
}
defer file.Close()
f, err := os.Create("filepath"))
if err != nil {
log.Fatal(err)
return err
}