Comments (9)
class CustomS3Storage(S3Storage):
def _save(self, name, content):
"""
We create a clone of the content file as when this is passed to boto3 it wrongly closes
the file upon upload where as the storage backend expects it to still be open
"""
# Seek our content back to the start
content.seek(0, os.SEEK_SET)
# Create a temporary file that will write to disk after a specified size
content_autoclose = self.new_temporary_file()
# Write our original content into our copy that will be closed by boto3
content_autoclose.write(content.read())
content_autoclose.file = content.file
# Upload the object which will auto close the content_autoclose instance
result = super()._save(name, content_autoclose)
# Cleanup if this is fixed upstream our duplicate should always close
if not content_autoclose.closed:
content_autoclose.close()
return result
storage = CustomS3Storage()
Seems to help
from django-s3-storage.
I'll push out a patch release momentarily
from django-s3-storage.
I'll push out a patch release momentarily
Hi, is there a solution for this? I get ValueError I/O while uploading to S3
from django-s3-storage.
from django-s3-storage.
Actually, it worked now. However I now get an UnicodeDecodeError at /api/jour-reports
Traceback (most recent call last):
File "/Users/jakobkarlstrand/Documents/Programming/weknowit/HaningeBostader/backend/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/jakobkarlstrand/Documents/Programming/weknowit/HaningeBostader/backend/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 145, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/jakobkarlstrand/Documents/Programming/weknowit/HaningeBostader/backend/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 143, in _get_response
response = response.render()
File "/Users/jakobkarlstrand/Documents/Programming/weknowit/HaningeBostader/backend/venv/lib/python3.9/site-packages/django/template/response.py", line 105, in render
self.content = self.rendered_content
File "/Users/jakobkarlstrand/Documents/Programming/weknowit/HaningeBostader/backend/venv/lib/python3.9/site-packages/rest_framework/response.py", line 70, in rendered_content
ret = renderer.render(self.data, accepted_media_type, context)
File "/Users/jakobkarlstrand/Documents/Programming/weknowit/HaningeBostader/backend/venv/lib/python3.9/site-packages/rest_framework/renderers.py", line 100, in render
ret = json.dumps(
File "/Users/jakobkarlstrand/Documents/Programming/weknowit/HaningeBostader/backend/venv/lib/python3.9/site-packages/rest_framework/utils/json.py", line 25, in dumps
return json.dumps(*args, **kwargs)
File "/opt/homebrew/Cellar/[email protected]/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 234, in dumps
return cls(
File "/opt/homebrew/Cellar/[email protected]/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/opt/homebrew/Cellar/[email protected]/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/Users/jakobkarlstrand/Documents/Programming/weknowit/HaningeBostader/backend/venv/lib/python3.9/site-packages/rest_framework/utils/encoders.py", line 50, in default
return obj.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 50: invalid start byte
from django-s3-storage.
from django-s3-storage.
Hi I am still seeing this issue in version 0.13.7 I will continue to investigate
from django-s3-storage.
@stumitchell Cab you let me know if this is fixed for you in the latest commit to the master branch?
from django-s3-storage.
For me it was the following error:
I tried to return the file, or information of the file, in a response. Check if you are doing something similar
from django-s3-storage.
Related Issues (20)
- Allow the storage to work in a Docker environment HOT 4
- How to delete record which used django-s3-storge HOT 3
- I am defined AWS_S3_ENDPOINT_URL in settings but still use default S3 endpoint url HOT 2
- if I am using rotated s3 credentials how do I setup credentials HOT 2
- Is there a way to get upload progress? HOT 4
- support for large file upload HOT 2
- Setting similar to `AWS_S3_KEY_PREFIX` but instead prepend a dynamic param for each model's files HOT 2
- Caching with pre-signed url HOT 7
- sha1 or other hash before upload? HOT 6
- Public-read buckets and AWS_S3_BUCKET_AUTH HOT 4
- Incompatibility issues with Django>=4.0 HOT 1
- Issue when upgrading to version 0.13.5 or higher HOT 4
- Huge Thanks HOT 2
- Update settings to define multiple S3 buckets HOT 1
- Document the `AWS_S3_MAX_POOL_CONNECTIONS` setting HOT 1
- Issues configuring AWS_S3_ENDPOINT_URL HOT 2
- Use Django's system check framework instead of log message HOT 1
- s3 bucket names being stored directly in migrations HOT 5
- Cannot open files in plain text mode HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-s3-storage.