Unknown file type MIME?
You can use application/octet-stream for unknown types. RFC 2046 states in section 4.5.1: The “octet-stream” subtype is used to indicate that a body contains arbitrary binary data.
You can use application/octet-stream for unknown types. RFC 2046 states in section 4.5.1: The “octet-stream” subtype is used to indicate that a body contains arbitrary binary data.
I hit this challenge today and I found these answers useful but not quite explicit enough for me. Edit: Just found the Apache Commons Email that wraps this up nicely, meaning you don’t need to know below. If your requirement is an email with: text and html versions html version has embedded (inline) images attachments … Read more
The python-magic method suggested by toivotuo is outdated. Python-magic’s current trunk is at Github and based on the readme there, finding the MIME-type, is done like this. # For MIME types import magic mime = magic.Magic(mime=True) mime.from_file(“testdata/test.pdf”) # ‘application/pdf’
There are a number of font formats that one can set MIME types for, on both Apache and IIS servers. I’ve traditionally had luck with the following: svg as “image/svg+xml” (W3C: August 2011) ttf as “application/x-font-ttf” (IANA: March 2013) or “application/x-font-truetype” otf as “application/x-font-opentype” (IANA: March 2013) woff as “application/font-woff” (IANA: January 2013) woff2 as … Read more
I did use urlmon.dll in the end. I thought there would be an easier way but this works. I include the code to help anyone else and allow me to find it again if I need it. using System.Runtime.InteropServices; … [DllImport(@”urlmon.dll”, CharSet = CharSet.Auto)] private extern static System.UInt32 FindMimeFromData( System.UInt32 pBC, [MarshalAs(UnmanagedType.LPStr)] System.String pwzUrl, [MarshalAs(UnmanagedType.LPArray)] … Read more
I’d recommend application/octet-stream as RFC2046 says “The “octet-stream” subtype is used to indicate that a body contains arbitrary binary data” and “The recommended action for an implementation that receives an “application/octet-stream” entity is to simply offer to put the data in a file[…]”. I think that way you will get better handling from arbitrary programs, … Read more
In Java 7 you can now just use Files.probeContentType(path).
I believe the standard MIME type for Excel files is application/vnd.ms-excel. Regarding the name of the document, you should set the following header in the response: header(‘Content-Disposition: attachment; filename=”name_of_excel_file.xls”‘);
For ASP.NET or other The options were changed a bit in ASP.NET Core, here they are (credits): new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType); (vNext only) Never tested, but looks like you can officially expand the mime types list via the exposed Mappings property. Use the MimeTypes NuGet package Copy the MimeMappings file from the reference source of … Read more
One possible solution uses JavaScript on the client. The client algorithm: Generate a random unique token. Submit the download request, and include the token in a GET/POST field. Show the “waiting” indicator. Start a timer, and every second or so, look for a cookie named “fileDownloadToken” (or whatever you decide). If the cookie exists, and … Read more