I
I
impressive172020-09-09 22:55:17
go
impressive17, 2020-09-09 22:55:17

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

Backend in golang. The server receives a multipart/form-data POST request c with a picture. I need to get this picture and save it on the server. Tell me how to do it? Preferably with code example)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
stormofication, 2020-10-07
@stormofication

Get this picture from *http.Request, by key (in this case "file"), then create a file and copy it 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
      }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question