imaging icon indicating copy to clipboard operation
imaging copied to clipboard

How to get file from postman

Open surapong-tho opened this issue 3 years ago • 2 comments

I'm newbie a developer How to get image from form data type file from api(postman)

surapong-tho avatar Oct 12 '21 17:10 surapong-tho

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

surapong-tho avatar Oct 12 '21 17:10 surapong-tho

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.

disintegration avatar Oct 24 '21 22:10 disintegration