matthewwithanm / django-imagekit

Automated image processing for Django. Currently v4.0
http://django-imagekit.rtfd.org/
BSD 3-Clause "New" or "Revised" License
2.24k stars 276 forks source link

S3 upload error if File doesn't have name #424

Open wtemmerman opened 7 years ago

wtemmerman commented 7 years ago

I have an error if I tried to upload a file without name, on S3 storage. The error message is not important.

S3Storage error at 'profiles/kiss.jpg': An error occurred (XAmzContentSHA256Mismatch) when calling the PutObject operation: The provided 'x-amz-content-sha256' header does not match what was computed.

And when I upload a profile picture for users, I used ProcessedImageField()on my field picture. But in imagekit/utils.py, the function generate() (line 146) create a File object without name. In traceback I can see <File: None>

But when I update line 153 of utils.py From : f = File(content) To : f = File(content, name=generator.source.name) Upload finish perfectly.

Maybe I miss something in S3 storage configuration, to accept File without name. I used django-s3-storage, last version, with boto3. Or do you want me to create a PR ?

vstoykov commented 7 years ago

Actually I never played with django-imagekit and S3 in the last 3-4 years. There are some changes in boto and the way how different 3th party storages works with boto in order to upload files to S3.

There was some issues related to boto3 (because of django-storages) and some people make it to work with django-s3-storage but before django-s3-storage started using boto3. Currently I don't have any observations of how ImageKit interact with these storages.

You can prepare a PR in order to see what changes fixed the problem for you and if it is ok and do not break other code we can merge it.

wtemmerman commented 7 years ago

Alright. Pull request #425 added.

charly06 commented 6 years ago

I had the same problem and got the same error message. Your fix worked for me, however I don't know if there are any side effects. At least I haven't recognized any.

apiljic commented 6 years ago

I am currently trying to switch from django-storages to django-s3-storage. While original file is stored at s3 correctly, the thumbnail is not created and not stored. The error I get is exactly the same as reported here.

wtemmerman commented 6 years ago

@apiljic The PR is still open. I guess the bug is not fix in the repo. Did you try my fix ?

apiljic commented 6 years ago

Yes. I just realized the PR is still open and edited my comment. I can confirm this error with:

django==1.11.12
django-imagekit==4.0.2
django-s3-storage==0.11.2
boto3==1.7.3

I haven't tested your solution yet. I need to try to understand what is going on. At the moment, I see an error with django-storages, like here: https://github.com/matthewwithanm/django-imagekit/issues/391

And the error you described with django-s3-storage. Can it be that both errors actually originate in boto3?

apiljic commented 6 years ago

@wtemmerman After upgrading django-s3-storage to the latest version (0.12.4), this error has been gone for me.