Closed wtemmerman closed 2 years ago
As the comment in the next line states we are trying to prevent reopening of the file because there will be an error. For some reason file was probably closed or something.
The value of generator.source.name
will point to original image and not the generated one. It is "working" for you (there is no exception) but I'm not sure that the right image is used all the time. We need to investigate this more deeply.
In this case, the name put in File() is not really important. I can do :
f = File(content, name='tmp_name')
and everything will be good
And in my S3 storage, the good name will be save, same in my database.
The strange thing is why it want a name at all and what happens with that name.
This needs further investigation. It may work for you but I'm not convinced that this is the right thing or right fix for it.
Can you add a full traceback in the linked issue (you can mask some paths if you want for privacy reasons) to see what is happening and where exactly it breaks.?
I will ask to django-s3-storages contributor if they have any idea about this problem.
DJANGO : 1.11.2 Django-s3-storage : 0.11.2
Traceback:
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django_s3_storage/storage.py" in _do_wrap_errors
30. return func(self, name, *args, **kwargs)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django_s3_storage/storage.py" in _save
249. self.s3_connection.put_object(Body=content, **put_params)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/botocore/client.py" in _api_call
253. return self._make_api_call(operation_name, kwargs)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/botocore/client.py" in _make_api_call
557. raise error_class(parsed_response, operation_name)
During handling of the above exception (An error occurred (XAmzContentSHA256Mismatch) when calling the PutObject operation: The provided 'x-amz-content-sha256' header does not match what was computed.), another exception occurred:
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/home/jestocke/Projets/jestocke/jestocke/dashboard/views.py" in post
394. saved_file = form.save()
File "/home/jestocke/Projets/jestocke/jestocke/dashboard/forms.py" in save
96. super(ProfilPictureUploadForm, self).save(commit=commit)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/forms/models.py" in save
451. self.instance.save()
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/contrib/auth/base_user.py" in save
80. super(AbstractBaseUser, self).save(*args, **kwargs)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/db/models/base.py" in save
806. force_update=force_update, update_fields=update_fields)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/db/models/base.py" in save_base
836. updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/db/models/base.py" in _save_table
900. for f in non_pks]
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/db/models/base.py" in <listcomp>
900. for f in non_pks]
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/db/models/fields/files.py" in pre_save
296. file.save(file.name, file.file, save=False)
File "/home/jestocke/Projets/jestocke/src/imagekit/imagekit/models/fields/files.py" in save
13. return super(ProcessedImageFieldFile, self).save(new_name, content, save)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/db/models/fields/files.py" in save
94. self.name = self.storage.save(name, content, max_length=self.field.max_length)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django/core/files/storage.py" in save
54. return self._save(name, content)
File "/home/jestocke/Projets/jestocke/lib/python3.5/site-packages/django_s3_storage/storage.py" in _do_wrap_errors
32. raise OSError("S3Storage error at {!r}: {}".format(name, force_text(ex)))
Exception Type: OSError at /mon-compte/upload_pp/20726/
Exception Value: S3Storage error at 'profiles/kiss_MoCZr84.jpg': An error occurred (XAmzContentSHA256Mismatch) when calling the PutObject operation: The provided 'x-amz-content-sha256' header does not match what was computed.
Request information:
FILES:
file = <InMemoryUploadedFile: kiss.jpg (image/jpeg)>
Issue #424