s3_1.py 530 B

12345678910111213141516
  1. def s3_upload(uploaded_file, id):
  2. s3conn = boto.connect_s3(AWS_ACCESS_KEY,AWS_SECRET_ACCESS_KEY)
  3. bucket = s3conn.get_bucket(S3_BUCKET)
  4. k = Key(bucket)
  5. k.key = 'id-' + str(id)
  6. k.content_type = uploaded_file.content_type
  7. if hasattr(uploaded_file,'temporary_file_path'):
  8. k.set_contents_from_filename(uploaded_file.temporary_file_path())
  9. else:
  10. k.set_contents_from_string(uploaded_file.read())
  11. k.set_canned_acl('public-read')
  12. return k.generate_url(expires_in=0, query_auth=False)