0

How can I upload file (that I get from formdata with AJAX) to S3 using boto? I'm trying to do this, but it doesn't work.

def upload_file(self, file):
    conn = S3Connection('xxxxxxxxxxxx', 'xxxxxxxxxxxx')
    bucket = conn.get_bucket('xxxxxxxx', validate=False)
    k = Key(bucket)
    k.key = file.filename

    k.set_contents_from_stream(f.body)
    k.set_metadata('Content-Type', 'application/pdf')
    k.set_acl('public-read')
    url = k.generate_url(expires_in=0, query_auth=False)
    return url
Yurii Kramarenko
  • 1,025
  • 6
  • 16
  • Duplicate of this http://stackoverflow.com/questions/38123504/boto2-file-upload-does-not-works/38252179#38252179 – Yonatan Kiron Jul 10 '16 at 20:41
  • It depends. What is the specific error message? – jkdev Oct 30 '16 at 21:12
  • @YonatanKiron - no. it's not a duplicate of that question. this question is in regards to the set_contents_from_stream method where as the question you linked to is an answer for the set_contents_from_filename method. – Alex Daro Nov 08 '16 at 01:36

0 Answers0