Reputation: 5214
I have a web application that accepts multipart/form-data and have set up api gateway to pass through the requests to it. However, any time I upload images as part of the form they end up being larger than the original file I uploaded and corrupted. If I execute the same method without going via AWS API gateway the image uploads fine. Any ideas what I'm missing here?
the below is my S3 code that reads the form data in flask:
f = request.files['attachment']
fp = StringIO(f.read())
file_uuid = str(uuid.uuid4())
bucketkey.key = "att_%s%s" % (file_uuid, file_extension(f.filename))
bucketkey.set_contents_from_file(fp)
I'll attach a link to a sample jpg that is corrupted if its useful at all.
Upvotes: 1
Views: 867
Reputation: 217
You need to set content-type header for your data to be recognized as binary by API Gateway.
Upvotes: 0
Reputation: 845
What is your intent with StringIO? f.read() will give you bytes, not a string. I think you can pass f directly to set_contents_from_file and it will read from f.
f = request.files['attachment']
file_uuid = str(uuid.uuid4())
bucketkey.key = "att_%s%s" % (file_uuid, file_extension(f.filename))
bucketkey.set_contents_from_file(f)
Upvotes: 1