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

S3BotoStorage doesn't properly fallback to other Content-Type heuristics #406

Closed
bxm156 opened this issue Oct 14, 2017 · 4 comments
Closed

Comments

@bxm156
Copy link
Contributor

bxm156 commented Oct 14, 2017

Content Type is determined by the following:

  1. a property called content-type
  2. the filename
  3. a default is used

If the content-type property doesn't exist, the logic falls back to 2 and 3. But the logic doesn't properly fallback if the content_type exists, but it set to None.

I found that in django my InMemoryFileUpload had a content_type of None. And so django-storages would try to make a s3 upload via boto3 with the following params {"Content-Type:": None}

This would cause boto to crash with

Invalid type for parameter ContentType, value: None, type: <class 'NoneType'>, valid types: <class 'str'>

@alexhayes
Copy link

@bxm156 Are you using django-filer to upload the file in the admin?

@willplaehn
Copy link

I encountered this issue today using the s3boto3 backend when dealing with a certain .ico file and reached the same conclusion as the OP. I'm not using django-filer

s3boto3.py 421

        _type, encoding = mimetypes.guess_type(name)
        content_type = getattr(content, 'content_type',
                               _type or self.default_content_type)

Could be changed to something like the following. Keeping the linebreaks for easier comparison:

        _type, encoding = mimetypes.guess_type(name)
        content_type = getattr(content, 'content_type',
                               None) or _type or self.default_content_type

What do you think?

@bxm156
Copy link
Contributor Author

bxm156 commented Nov 14, 2017

@alexhayes Yes, I was using django-filer. However it seems like @willplaehn is not.

@Alir3z4
Copy link

Alir3z4 commented Dec 1, 2017

I'm using Django Filler as well, and this is happening for me as well

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

4 participants