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

sync image processing with django-storages #29

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,23 @@ class PictureSerializer(serializers.Serializer):

`PictureField` is compatible with [Djang Cleanup](https://github.com/un1t/django-cleanup),
which automatically deletes its file and corresponding `SimplePicture` files.

### Django Storages

When using [Djang Storages](https://github.com/jschneier/django-storages) with S3 Backend and sync image processing, it is necessary to adapt the storage class.
This is due to `boto3` closing the temporary file after upload, making it unavailable for image processing.
The modified `_save` method is taken from `S3ManifestStaticStorage`:

```python
from storages.backends.s3boto3 import S3Boto3Storage
import tempfile

class MediaStorage(S3Boto3Storage):
def _save(self, name, content):
content.seek(0)
with tempfile.SpooledTemporaryFile() as tmp:
tmp.write(content.read())
return super()._save(name, tmp)
```

More details on overriding the default storage class: https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#overriding-the-default-storage-class