dennisv / django-storage-swift

OpenStack Swift storage backend for Django
MIT License
86 stars 59 forks source link

Files are getting uploaded but while fetching 401 Unauthorized error. #105

Closed shubhamc183 closed 3 years ago

shubhamc183 commented 6 years ago

I have set the swift storage as

DEFAULT_FILE_STORAGE = 'swift.storage.SwiftStorage'
STATICFILES_STORAGE = 'swift.storage.StaticSwiftStorage'

SWIFT_AUTH_URL = os.environ.get("SWIFT_AUTH")
SWIFT_USERNAME = os.environ.get("SWIFT_USER")
SWIFT_KEY = os.environ.get("SWIFT_KEY")
SWIFT_CONTAINER_NAME = os.environ.get("SWIFT_CONTAINER")
SWIFT_STATIC_CONTAINER_NAME = os.environ.get("SWIFT_CONTAINER")

And I am able to do a normal file upload and collectstatic but getting error while fetching the file.

Somehow, the keys are not getting mapped in HTTP Headers I guess...!

Can I add media folders also?

shubhamc183 commented 3 years ago

Closing this ticket due to inactivity.

o-s-m-o-s commented 10 months ago

Old issue but I was trying to do this stupid thing and wasted an hour. The static files container has to be public as use_temp_urls is set to False on the StaticSwiftStorage class and so the temp_key doesn't get passed in the GET request and hence the request is denied.

class StaticSwiftStorage(SwiftStorage):
    container_name = setting('SWIFT_STATIC_CONTAINER_NAME', '')
    name_prefix = setting('SWIFT_STATIC_NAME_PREFIX', '')
    auto_base_url = setting('SWIFT_STATIC_AUTO_BASE_URL', True)
    override_base_url = setting('SWIFT_STATIC_BASE_URL')
    auto_create_container_public = True
    use_temp_urls = False

You can subclass and overrule this, but why bother? Make the static files container public instead since it's so easy to create separate containers and it's static files so why waste cycles generating access signatures for every file.