Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuspiciousOperation when using S3 #12

Open
andreiavram opened this issue Aug 1, 2014 · 0 comments
Open

SuspiciousOperation when using S3 #12

andreiavram opened this issue Aug 1, 2014 · 0 comments

Comments

@andreiavram
Copy link

There's a catch when using S3 as your storage backend - saving and retrieving photos works as you would expect, but when trying to clear the cache folder (for example after rotating the photo) and maybe in some other cases, _get_SIZE_filename() is called, and that in turn returns a path based on MEDIA_ROOT - causing a SuspiciousOperation at least in Django 1.4 and above.

The code in issue is in photologue/models.py:

    def _get_SIZE_filename(self, size):
        photosize = PhotoSizeCache().sizes.get(size)
        generator = PhotologueSpec(photo=self, photosize=photosize)
        return os.path.join(settings.MEDIA_ROOT, generator.cachefile_name)

For my use case, where I needed to be able to delete cached sized versions of images, overriding the _get_SIZE_filename method with something like

    def _get_SIZE_filename(self, size):
        photosize = PhotoSizeCache().sizes.get(size)
        generator = PhotologueSpec(photo=self, photosize=photosize)
        return generator.cachefile_name

but there should be a better way of dealing with this in an storage independent kind of way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant