django - Files uploaded to S3 with S3BotoStorage end up with invalidly escaped content-type meta data -
facepalm update: turns out had forgotten/overlooked fact using older fork of s3botostorage https://github.com/gtaylor/django-athumb default storage (even though had django-storages installed). current version of django-storages doesn't suffer problem. problem content-type headers unicode when hit boto, , boto escapes unicode using urllib.quoteplus
before sending on aws. isn't boto's fault since headers have converted non-unicode strings somehow per http. more indepth analysis see https://github.com/boto/boto/issues/1669 .
original question
i using django_storage's s3botostorage in conjunction filefield upload files amazon s3. here's field:
downloadable_file = filefield(max_length=255, upload_to="widgets/filedownloads", verbose_name="file")
in settings:
default_file_storage = 'storages.backends.s3boto.s3botostorage'
everything works far uploading/downloading goes.
however, files getting stored in bucket incorrect content-type. wheni @ metadata files in aws s3 console, content-type of file showing "application%2fpdf" instead of "application/pdf" should be.
in case shouldn't matter, matter. google chrome's built-in pdf reader hang on pdf's invalid content-type, , client brought attention.
here's example of file uploaded through django-storages/boto. if you're using chrome's built-in pdf reader assume hangs, me , customer reported this. if you're using non-chrome browser, or adobe plugin, or downloading file disk you'll fine.
if manually change content-type metadata via aws console 'application/pdf' (one of standard choices provides) fine.
i assume bug internal way boto constructs aws policy document upload file, since i'm not doing outside of standard usage here. however, i've stepped through boto code , can't find escaping.
can either suggest work around, or guide me offending code in boto can patch , submit pull request?
boto==2.9.5 django-storages==1.1.8
not direct answer question, maybe useful workaround. having issues using django-storages s3. ended trying cuddly-buddly , have been quite happy it. author based on s3 module django-storages , has added quite number of fixes. browsed through cuddly-buddly commits , there modifications affecting content-type header, can't test pdf uploads without setting new django project. however, can verify files uploaded through django not have mangled slashes in content-type field in s3 metadata.
if reason can't change on cuddly-buddly testing, let me know , i'll try setup simple django project upload pdfs.
Comments
Post a Comment