Skip to content

Instantly share code, notes, and snippets.

@tejiriaustin
Created June 14, 2022 23:19
Show Gist options
  • Save tejiriaustin/b0cc6ce2136c3060f07eb4810214dd16 to your computer and use it in GitHub Desktop.
Save tejiriaustin/b0cc6ce2136c3060f07eb4810214dd16 to your computer and use it in GitHub Desktop.
if err := ctx.BindJSON(&payload); err != nil {
ctx.String(http.StatusBadRequest, "bad request type")
return
}
ctx.MultipartForm()
file, _, err := ctx.Request.FormFile(payload.FileName)
if err != nil {
h.logger.Err(err).Msgf("Error in payload: %s", err)
ctx.String(http.StatusInternalServerError, "error parsing file")
return
}
defer file.Close()
tempFile, err := ioutil.TempFile("temp-images", "upload-*.png")
if err != nil {
ctx.String(http.StatusInternalServerError, "read error")
return
}
defer tempFile.Close()
fileBytes, err := ioutil.ReadAll(file)
if err != nil {
ctx.String(http.StatusInternalServerError, "error parsing filebytes")
return
}
tempFile.Write(fileBytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment