There are a lot of webpages designed to show one how to upload a file to amazonaws s3 using boto3 but what if you want to make changes to an object after you open it and it would be time consuming and wasteful to export the object as a file? So I tracked down the syntax and it appears that what you need to do is:
s3_client = boto3.client('s3',
region_name='us-east-1',
aws_access_key_id='zzz',
aws_secret_access_key='zzz')
b = 1
s3_client.put_object(Body=b, Bucket='hey_you1111', Key='you')
Incidentally, I'm trying to upload mp3 objects, most of them are 10 seconds long or so, but amazon transcribe speeds up the longer the mp3s are so I have to combine several mp3s, then upload them which is why I don't feel like exporting the combined mp3s to a file, though it would not be too bad if that's what I have to do anyway. It seems that put_object
can only handle bytes-objects. So now I need to find out if that's really true or if I can convert mp3 objects to bytes. I haven't found any websites yet which teach how to convert mp3 objects to bytes, but plenty for teaching how to convert bytes to mp3. I'd rather be able to just upload the mp3 object to s3 directly since I'll probably get an error message when I got to transcribe it. Here's the error message I get when I try to upload the mp3:
Invalid type for parameter Body, value: <pydub.audio_segment.AudioSegment object at 0x1290a7040>, type: <class 'pydub.audio_segment.AudioSegment'>, valid types: <class 'bytes'>, <class 'bytearray'>, file-like object