imaging
imaging copied to clipboard
How to get file from postman
I'm newbie a developer How to get image from form data type file from api(postman)
log := logger.WithPrefixFunctionName()
file, err := c.FormFile("file")
if err != nil {
log.CErrorln(c,"Get file error, ", err)
return err
}
log.Println(file)
//image, err := file.Open()
//if err != nil {
// log.CErrorln(c, "Open file error, ", err)
// return err
//}
src, err := imaging.Open(file.Filename)
if err != nil {
log.CErrorln(c, "Open file error, ", err)
return err
}
src = imaging.Resize(src, 200, 0, imaging.Lanczos)
// Save the resulting image as JPEG.
err = imaging.Save(src, "testdata/out_example.jpg")
if err != nil {
log.CErrorln(c, "failed to save image: %v", err)
return err
}
return nil
this is my code thx
Hi,
What type is c
in your example?
file, err := c.FormFile("file")
The FormFile method of http.Request from standard library returns a multipart.File
(https://pkg.go.dev/net/http#Request.FormFile). You can pass it to imaging.Decode
to decode the image.