0

I wanted to upload file to s3 using python. I am using requests_aws4 auth library for this

    import requests
    from requests_aws4auth import AWS4Auth
    # data=encode_audio(data)
    endpoint = 'http://bucket.s3.amazonaws.com/testing89.mp3'
    data = //some binary data(mp3) here
    auth = AWS4Auth('xxxxxx', 'xxxxxx', 'eu-west-2', 's3')
    response = requests.put(endpoint,data=data, auth=auth,  headers={'x-amz-acl': 'public-read'})
    print response.text

I have tried the above code and got the following error. 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128).

This works fine if I send text data since it is also ascii but when the binary data is being sent I think there is some concatenation error of binary data with auth data. Am I wrong somewhere? Someone please guide me. Thanks.

coolguy
  • 5
  • 3
  • take a look at `base64-encode` and `base64-decode`. – luoluo Apr 21 '17 at 09:24
  • yeah but converting to base64 encoding requires us to decode the data again once we download from that url. Is there any way to upload raw binary data to s3 so that people could use the link directly – coolguy Apr 21 '17 at 09:30
  • take a look at [this post](http://stackoverflow.com/a/14448953/1099230). Maybe you need update your header. – luoluo Apr 21 '17 at 09:33
  • I tried sending the same binary data without auth data to a local server. Worked fine. so I think no problem with binary data but some problem concatenating binary data with auth data. – coolguy Apr 21 '17 at 09:57

0 Answers0