What MIME-type to use as general purpose? - mime-types

I have a PHP script that I use to download different types of files (PDF, JPEG, RAR end other). Works great, however I noticed an issue there with the MIME-type.
Is there a universal MIME-type I can safely use for "general purpose"? I am thinking of application/octet-stream for all file types.
Or should I do the MIME for each file type individually?
It's supposed to deliver downloads, it's not important to open the files in apps directly.

If you just want to deliver files and don't care about the type of application needed to open it, then it's safe to specify the file mime type as application/octet-stream. However you should specify that it should be saved and should not be attempted to be opened inline within the browser.
you should specify the header as:
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="file.png"
It informs the browser (or the client application) that the file should be downloaded and should not be attempted to be opened inline.

Related

ng2-file-upload doesn't work when I do not have office installed

I tested the ng2-file-upload on my vm without any office installed, and I am trying to upload a file with a file type of .doc & .docx and it keeps me going to this condition ->
this.uploader.onWhenAddingFileFailed = (item, filter, options) => { }
is there a workaround on this to work without me having to install office at all?
Your OS doesn't have any predefined specific mime type. It doesn't know how to open .docx/.xlsx/.ppt files. These mime types will be added to your OS with special soft.
Browser sets application/octet-stream as mime type of your file
So, your back-end should have two different scenarios on file-upload, where it should check mime type or file extension

Firefox ignores "video/quicktime" MIME Type for file input

I have a form with a file input to handle file uploads for images or videos. I want to restrict the accepted file-types to .jpg, .gif, .png, .mp4 and .mov, so I'm using the accept option on my input type="file" as follows:
<input name="message[file]" accept="image/jpeg,image/png,image/gif,video/mp4,video/quicktime" type="file">
This works basically fine, but Firefox seems to ignore the video/quicktime MIME type and the file dialog box shows the .mov files as unavailable. All the other accepted file types are available.
I can select the .mov files when I use video/* as accepted file-types, but I want to restrict the video-uploads to .mp4 and .mov. According to my research video/quicktime is the correct MIME type for .mov files and the WebKit-Browsers work well with it. Why would Firefox not accept the .mov files?
Only MP4, WebM, and Ogg video are supported by the HTML5 standard. Starting from Firefox 45, video/quicktime content type is treated as MP4 media to be handled by the built-in HTML5 video player. But MOV files can contain a variety of different encodings, they are not all MP4.

Send Office Open XML file in response

I'm trying to send the content of an Open Office XML file in the response but I can't get the browser to recognize the file and open it with word. It keeps opening it as it was an XML file. I've tried setting the content type to both application/msword and application/vnd.openxmlformats-officedocument.wordprocessingml.document, I've also tried setting the extension to doc and docx, but nothing seems to work.
It sounds like you may be confusing "Open Office" documents with MS Office "Open XML" documents.
The former is a truly open standard (OpenDocument), which can be a single XML file, but is typically a Zipped archive of xml files and binary attachments.
The latter is a similar, but different format, that has been through the standardization process (it is an official ECMA standard), but which has gotten little adoption outside of the MS Office suite. The standardization process was very political - I'll leave it to you to look it up if you are interested.
MS Word, since 2007 SP2 can open OpenDocument (Open Office) .odt files, but I don't think that it works with the single-xml format.
So, try the .odt format.
Also, be aware that Internet Explorer tends to ignore MIME Type, and uses the file extension instead. So you should set the correct MIME Type: application/vnd.oasis.opendocument.text
and set the file name to something ending in ".odt"

IE6 "helpfully" appends suffix to downloaded file

A webapp I've been developing allows users to upload and download a type of file which is meant to be treated as an opaque blob. My app serves it up with a file extension not commonly used for any other purpose, as well as specifying that its MIME Content-Type is application/octet-stream.
Internally, the file is a simple Zip archive containing a single compressed file. What I've found is that IE6 apparently inspects the content of the file, determines that it's a Zip archive, and "helpfully" saves it with an additional ".zip" extension. Unbelievable!
As I mentioned, this file is meant to be opaque, and we don't want users to be poking around inside the file--not because it's dangerous or contains sensitive information or anything, we just don't want to confuse them. I suggested prepending the Zip content with a magic number to prevent IE6 from recognizing it, but my manager says he'd prefer it if the file content could remain unchanged, so that knowledgeable people can rename the file and examine its contents as a zip archive, if necessary.
Is there any way to tell IE6 to keep its mitts off of the file? Or any alternative approach at all? (Alas, just not supporting IE6 at all is not an option.)
Incidentally, IE7 respects the file's name, but still identifies it as a Zip archive in the download dialog. That's better than IE6, but still less than ideal.
Short answer: Add correct MIME types to you web server so IE6 doesn't guess the file type.
Long Answer:
My work had a similar problem with Microsoft PowerPoint files.
.ppt vs .pps - Which are identical files with different extensions. We wanted the user to view a show (.pps) but IE6 kept changing it to .ppt. It changed the extention because the users machine had PowerPoint installed and understood that the file "looked" like a . ppt. Don't understand why not .pps.
The problem, besides IE6, was that our web server (IIS) was not aware of either MIME types for .pps or .ppt. So we had to add the correct MIME types so the server would not deliver them as "application/octet-stream". I understand that by using "application/octet-stream" IE6 will try to guess the MIME type.
So we added:
.pps = "application/vnd.ms-powerpoint"
.ppt = "application/vnd.ms-powerpoint"
Now it works fine with IE6.
I hope this helps solve your problem.
use this header flag: Content-Disposition: attachment; filename="yourfilename.extension"
This is a known problem, and the only solution is to edit the client computer's registry, which I'm sure doesn't help you a lot.

Why does IE7 specify a mime-type of image/pjpeg rather than just image/jpeg?

When uploading a file (jpeg) via a form in IE7 I am seeing a mime-type of "image/pjpeg" instead of "image/jpeg" (as I see in Firefox or similar). It's easy enough to work around this problem, but I'm just wondering why IE7 is behaving differently in this case?
I believe it's because the JPEG you're working with is a progressive JPEG, which has a different mime-type.
IE can upload all .jpeg files as its hack MIME type 'image/pjpeg' regardless of whether or not they're actually progressive.
Don't rely on the MIME type supplied in a file upload, there is every chance it could be wrong for a variety of reasons including this one.
Because Microsoft likes to violate standards. There's no such MIME type as image/pjpeg. See for yourself:
http://www.iana.org/assignments/media-types/media-types.xhtml#image
The correct MIME type for JPEG is image/jpeg, progressive or not.
There is same problem with png:
IE7: image/x-png
Normal browsers: image/png
;)

Resources