Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get file from postman #150

Open
surapong-tho opened this issue Oct 12, 2021 · 2 comments
Open

How to get file from postman #150

surapong-tho opened this issue Oct 12, 2021 · 2 comments

Comments

@surapong-tho
Copy link

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

@surapong-tho
Copy link
Author

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

@disintegration
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants