google / skicka

Command-line utility for working with Google Drive. Join the mailing list at https://groups.google.com/forum/#!forum/skicka-users.
Apache License 2.0
1.3k stars 118 forks source link

Do not guess MIME type when uploading #132

Closed agoode closed 5 years ago

agoode commented 5 years ago

http.DetectContentType() implements the MIME sniff algorithm at https://mimesniff.spec.whatwg.org/. This is not really the correct algorithm to use for uploading files to Google Drive. Files such as .xlsx, .pptx, .docx, .apk, and other ZIP-based formats are incorrectly uploaded as plain ZIP files and cannot be viewed properly at drive.google.com.

Uploading as application/octet-stream allows the server to automatically detect the content type with a better algorithm that has much better results. I tested with apk, docx, zip, pdf, jpg, gif, png, html, txt, wav, and xml.

Before this change, I could not properly view/play wav or docx. apk files also showed up as plain ZIP. With this change, these files render correctly. The other files continued to work.

Type MIME before MIME after
wav audio/wave audio/x-wav
apk application/zip application/vnd.android.package-archive
docx application/zip application/vnd.openxmlformats-officedocument.wordprocessingml.document
zip application/zip application/zip
pdf application/pdf application/pdf
jpg image/jpeg image/jpeg
gif image/gif image/gif
png image/png image/png
html text/html text/html
txt text/plain text/plain
xml text/plain application/xml

Closes #104.