Created
June 14, 2022 23:19
-
-
Save tejiriaustin/b0cc6ce2136c3060f07eb4810214dd16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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