I want to stream multipart file directly to AWSS3 instead of saving file to disk at first. Receiving file of type *multipart.FileHeader in my golang REST API. Now I want to stream this to AWSS3, using s3manager upload method where it's required to pass *bytes.Reader in body param. I have seen an example of uploading file to AWSS3, written in a way that opening a file os.Open("filepath") of type *os.File from disk,getting *bytes.Reader out of it and passing to AWSS3. Now I am struggling to convert this *multipart.FileHeader to *os.File.
Call Open on the multipart.FileHeader
. It will return a multipart.File
which will provide a reader to the file (which will be held in memory).
you can use os.Open() to convert multipart.FileHeader to *(os.File)
example
_, header , _ := c.Request.FormFile("upload")
out, _ := os.Open(header.Filename)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With