Signature Does Not Match Odd Issue
dcantah opened this issue · comments
A bit of an odd problem I'm having .mp3/.wav/.m4a all give 403 errors https://imgur.com/a/dqZthvy and give this message https://i.stack.imgur.com/2BHdW.png . However, any other type of file works and I can place it in an directory path I want. I've tried html/js/png/jpg/pdf/mp4 and they all upload fine, but the returned url still says signature does not match regardless of the successful upload which is odd to me. I've quadruple checked my access keys so thats out of the question and I will link pictures to my iam and bucket policies but I believe it's most likely at an application level but I'm praying it could just be a quick policy fix which is why I'm posting here. I am using a package called react s3 uploader to grab the signed url and upload if anyones familiar with it. I've been tearing my hair out trying to solve this for the past day so any help is appreciated.
BUCKET POLICY: https://i.stack.imgur.com/lQoK1.png
IAM POLICY: https://imgur.com/a/mwhOJKj
Django Boto code: https://imgur.com/a/Wd16EfT
React S3 Uploader Component Code: https://i.stack.imgur.com/17Rvl.png
@dcantah Hi Bro, I also encountered this odd problem. I can upload video/webm files to S3 successfully while the audio/webm files not work. It's very strange. Could you please share your approach on solving this problem. Thanks!
@xuliang2019 Oh gosh it's been forever as you can see but I will try and see what I did back then and get back to you. I can't even remember what I was using this for even 😆 Feel free to ping again if I don't reply in a day or so but I'll try and find the project
@dcantah , Hi Danny, I just figured it out. It is the reason that the the file type of recorded audios in the frontend doesn't match the file type parsed by mimetypes.guess_type(object_name)[0]
in the backend. Thererfore, I acquire the Content-Type
of recorded audios using the request.GET
method, instead. Below is my full code:
import boto
import json
...
conn = boto.connect_s3('AWS_KEY', 'AWS_SECRET')
def sign_s3_upload(request):
object_name = request.GET['objectName']
content_type = request.GET['contentType']
# content_type = mimetypes.guess_type(object_name)[0]
signed_url = conn.generate_url(
300,
"PUT",
'BUCKET_NAME',
'FOLDER_NAME' + object_name,
headers = {'Content-Type': content_type, 'x-amz-acl':'public-read'})
return HttpResponse(json.dumps({'signedUrl': signed_url}))
Finally, thank you for your quick response!
@xuliang2019 Awesome, glad you got it figured out :)