0
votes

I'm working on Python Twilio app and using Amazon Polly to convert text to speech. As you may know, Twilio <play> verb can play sound files only from url. Now I can convert the text to speech audio with Amazon Polly and upload the audio file to S3 and let Twilio play it with public url.

But when I use boto3 to upload the mp3 files to S3, the content types are changed to binary/ octet-stream which is not supported by Twilio. I tried to use content-type parameter in boto3 but didn't work out. When I use tinys3 library, it works. However, I cannot upload the file to S3 subdirectory. Tinys3 can only upload to bucket. I googled but haven't seen any example about tinys3 uploading a file to S3 subdirectory.

So could you please help me out in either content type issue with boto3 or uploading a file to S3 subdirectory in a bucket with Tinys3?

1

1 Answers

0
votes

In AWS S3 everything within a bucket is considered as an object. There's nothing like you can't upload to sub directory. test_subdir/test_file.txt is treated as just an object in a S3 bucket.

Uploading a file to S3 subdirectory in a bucket with Tinys3:

import tinys3
conn = tinys3.Connection(S3_ACCESS_KEY, S3_SECRET_KEY,tls=True)

f = open('test_file.txt','rb')
print (conn.upload('test_subdir/test_file.txt',f,'test_bucket'))
print (conn.get('test_subdir/test_file.txt','test_bucket'))

Expected output: enter image description here