tools.py 606 B

1234567891011121314151617181920212223242526272829
  1. import boto3
  2. from app import app
  3. s3 = boto3.client(
  4. "s3",
  5. aws_access_key_id=app.config['S3_KEY'],
  6. aws_secret_access_key=app.config['S3_SECRET']
  7. )
  8. def upload_file_to_s3(file, bucket_name, acl="public-read"):
  9. try:
  10. s3.upload_fileobj(
  11. file,
  12. bucket_name,
  13. file.filename,
  14. ExtraArgs={
  15. "ACL": acl,
  16. "ContentType": file.content_type
  17. }
  18. )
  19. except Exception as e:
  20. print("Something Happened: ", e)
  21. return e
  22. return "{}{}".format(app.config["S3_LOCATION"], file.filename)