I'm adding a feature for downloading files from web servers. I'm testing my program with my own Google Drive account, but I'm not sure how I should deal with the Content-Type Header because I don't know much about web programming.
Firstly, I uploaded two files to my google drive account. Both were the exactly same zip files but I renamed the extension of one of them from "zip" to "ktx" which means nothing before uploading just for the test. After uploading, I checked Content-Type headers of them and got "application/zip" for the original one and "application/x-zip" for the renamed one.
I was confused so searched for the Content-Type Header but just got more confused. Because it seems there are more names for a zip, such as "multipart/x-zip" and "application/x-zip-compressed". So I really want to know if there's a standard naming convention for the Content-Type header.
Anyways I uploaded all the file types I need and below is what I got from Google Drive.
Documents
text/plain (txt)
application/pdf
application/msword (doc)
application/vnd.ms-powerpoint (ppt)
application/vnd.ms-excel (xls)
application/rtf
application/vnd.openxmlformats-officedocument.wordprocessingml.document (docx)
application/vnd.openxmlformats-officedocument.presentationml.presentation (pptx)
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (xlsx)
Images
image/jpeg
image/png
image/gif
image/tiff (tif, tiff)
image/x-ms-bmp
image/x-photoshop (psd)
image/x-raw (raw)
application/illustrator (ai)
Compressed
application/zip
application/rar
application/x-tar (tar)
application/x-gzip (gz)
application/x-7z-compressed (7z)
application/x-zip (When zip, jar, xlsx or apk is renamed to meaningless one.)
Audio files
audio/mpeg (mp3)
audio/x-wav
audio/x-ms-wma
audio/x-aiff (aiff)
audio/midi (mid)
application/ogg
Videos
video/mp4
video/x-msvideo (avi)
video/x-ms-asf
video/flv
video/quicktime (mov)
video/mpeg (mpg, vob)
video/x-ms-wmv
video/x-matroska (mkv)
Script or Source code files
text/html (htm, html)
text/x-csrc
text/x-c++src
text/x-csharp
text/x-java
text/x-python
text/css
application/x-javascript (js)
application/x-httpd-php
application/json
application/xml
Compiled or Executables
application/x-msdos-program (exe, dll, com, bat)
application/java-vm (class)
application/java-archive (jar)
application/x-python-code (pyc)
application/vnd.android.package-archive (apk)
Etc
application/x-shockwave-flash (swf)
Is there any standard naming convention?
Is it okay just to use the names above to check the MIME type?
Is there any standard naming convention?
Is it okay just to use the names above to check the MIME type?
For the standard types, see Iana Media Types.
For MIME types, see Iana MIME Media Type Parameters.
[RFC2046] specifies that Media Types (formerly known as MIME types) and Media Subtypes will be assigned and listed by the IANA.
The file types are determined once when uploading or the server always checks when downloading?
Normally, when the file is requested, the server will check the file extension and determine the media type to use. Some servers however might check the first bytes of the file (magic number) to determine what the file type is (for example, zip-files start with PK.. - dots being 0x03 0x04).
This is likely the reason you are seeing "application/zip"
for .zip
and "application/x-zip"
for zipped .ktx
. As a side note: .xlsx
is a zipped file too.
Depending on the implementation, the server might check this once when receiving the file, and store it for later use, or check it with each download.