'How to point Flask static to Digitalocean spaces
I am using url_for in my html pages to access and display static images. I wish to connect flask static to digitalocean spaces instead of AWS S3 as explained in this question.
I expect that after connecting to digital ocean spaces, the url_for would replace:
original path: static/folder1/image.JPG to
digital ocean spaces: https://{do_space_name}.sgp1.digitaloceanspaces.com/static/folder1/image.JPG
I have tried Flask-S3 SDK - assuming "Spaces is an S3-compatible object storage service"
from flask_s3 import FlaskS3
app.config['AWS_ACCESS_KEY_ID'] = 'aaaaaaaaaaaaaa'
app.config['AWS_SECRET_ACCESS_KEY'] = 'xxxxxxxxxxxxxxxxxxx'
app.config['FLASKS3_BUCKET_DOMAIN'] = 'sgp1.digitaloceanspaces.com'
app.config['FLASKS3_BUCKET_NAME'] = 'do_space_name'
s3 = FlaskS3(app)
This generates and replaces the path I expected, but in html it shows error 403 - (Forbidden)
My setting for digitalocean spaces are as below:
File Listing: Enable
File Listing (Anyone can list the contents of this Space) CDN (Content
Delivery Network): disables CORS Configurations: not set
Does it make sense to even attempt something like this? Is there any alternative approach or SDK that can help achieve this?
Solution 1:[1]
Turns out - this is worth couple of days worth of stupidity...but that's ok. Answering myself just in case someone stumbles upon:
1: Forbidden error is thrown because my static files in DO spaces was not marked as Public :)
2: I was under (obviously wrong) impression that if I give access key and secret key as config then I need not worry about file level permission
3: But turns out that you can connect to DO spaces even without these, hence what matters is the file level access.
4: For html webpage to access static files, then need to be public.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mandar |