I am using Golang as a restful api. I have an IOS app that user's upload photos afterwards the image is sent to Golang and it processes the image and uploads it (to Amazon s3), therefore the images are not found in my local directory . I was using the FormFile before to read the images such as
func s3ImageUpload(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
file, handler, err := r.FormFile("file")
if err != nil {
fmt.Println("Error Uploading Image")
return
}
// Rest of Code that uploads Image to my Amazon s3 Bucket no issues here
}
The problem with the above code is that sometimes Images as big as 4MB were being uploaded and that was too big so I got a new package to resize images https://www.github.com/disintegration/imaging . I posted on this yesterday and received great help and managed to upload images found on my local directory, however I need to find how to load images coming externally . The only issue I been having is with the Open method of this package and according to go-docs this is the explanation of that method
func Open
func Open(filename string) (image.Image, error)
Open loads an image from file
so if I have an image in my local directory and want to resize it I can do this
file_open,err := imaging.Open("/Users/IH/Documents/pictures/BigTurtle.jpg")
if err != nil {
print("Imaging Open error")
}
new_image := imaging.Resize(file_open, 300, 300, imaging.Lanczos)
// rest of code sends new image to Amazon s3 it works correctly That all works but as stated before the images are coming externally from other people's IOS devices so I can not put in an image path. I have tried to do this
file_open,err := imaging.Open(handler.filename)
and
file_open,err := imaging.Open("file")
but it states no image or directory found, I am new to Golang but is there some way that I can get the external file being sent into imaging.open ? I need that one because the 1st parameter of the method `imaging.Resize() is of type image.Image which is the same type as imaging.Open . Unfortunately the r.FormFile("file") is of type Multipart.File and can not be resized at least not to my limited knowledge. Any help would be great .