Thursday, 15 August 2013

Files uploaded to S3 with django_storage's S3BotoStorage end up with invalidly escaped content-type meta data

Files uploaded to S3 with django_storage's S3BotoStorage end up with
invalidly escaped content-type meta data

I am using django_storage's S3BotoStorage in conjunction with a FileField
to upload files to Amazon S3. Here's my field:
download_link = FileField(max_length=255,
upload_to="widgets/filedownloads", verbose_name="file")
In settings:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
Everything works as far as the uploading/downloading goes.
However, the files are getting stored in my bucket with an incorrect
content-type. The Content-Type of the file is "application%2Fpdf" instead
of "application/pdf" which it should be.

In case you say it shouldn't matter, it does matter. Google chrome's
built-in pdf reader will hang on pdf's with an incorrect content-type,
which is how this was brought to my attention.
Here's an example of a file uploaded through django-storages/boto.. If
you're using a non-chrome browser, or the adobe plugin or downloading the
file to disk you'll probably be fine. If you're using chrome's built-in
pdf reader, i assume it hangs like it does for me and the customer who
reported this. If I manually change the metadata to content-type
'application/pdf' then its fine.
I assume this is a bug with something internal with the way boto uploads
the files and the metadata, since I'm not doing anything outside of the
standard usage here. However, I've stepped through boto code and can't
find where it actually does the escaping.
Can someone either suggest a work around, or guide me to the offending
code in boto so I can patch it and submit a pull request?
boto==2.9.5 django-storages==1.1.8

No comments:

Post a Comment