By owlcoolrule
I need files I upload to be public. Is there a way to set a default so every file you upload is public? Otherwise, is there a way you can set a file to public using boto3 or a Python library?
Thanks in advance!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
To set a file as public with boto3 for DigitalOcean Spaces, you can set the ACL (Access Control List) while uploading the file to ‘public-read’. This will make the file accessible to the public. Here’s a sample code:
- import boto3
-
- s3 = boto3.client('s3',
- region_name='nyc3',
- endpoint_url='https://nyc3.digitaloceanspaces.com',
- aws_access_key_id='YOUR_ACCESS_KEY',
- aws_secret_access_key='YOUR_SECRET_KEY'
- )
-
- s3.upload_file('FILENAME', 'bucketname', 'objectname', ExtraArgs={'ACL':'public-read'})
However, to set a default policy making all uploaded files public, you would need to set a bucket policy that allows public read access to objects.
Please note that making a bucket public can have serious security implications and should only be done if you are sure this is what you want.
You can find more details about interacting with Spaces using boto3 in our DigitalOcean Spaces API documentation.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.