IE and Edge are ignoring application/octet-stream MIME Type - apache

Recently I've created a subdomain for downloads and I want the browser to download files instead of viewing it. For this I've added the following line into the .htaccess file:
AddType application/octet-stream .txt .png .jpg .jpeg .gif .exe .zip .rar .gz .sh .bat .doc .docx
On Firefox and Google Chrome it works but both Microsoft browser - Internet Explorer and Microsoft Edge are ignoring the MIME-Type and viewing them instead. How I also can force them to also download the files?

I can see that you had added all the file types in single line. So you can try to add them in separate line to check whether it solves your issue or not.
Based on my search, I find that IE can work with code below. So you can also make a test with it.
# Force PDF Download instead of display
<FilesMatch "\.pdf$">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
## End Force PDF Download instead of display
Reference:
Forcing a file to download in a browser via htaccess
If you are using PHP than you can try to refer approach below.
PHP allows you to change the HTTP headers of files that you’re writing, so that you can force a file to be downloaded that normally the browser would load in the same window. This is perfect for files like PDFs, document files, images, and video that you want your customers to download rather than read online. Using PHP you can take advantage of the PHP built-in readfile function:
$file_url = 'http://www.example.com/file.pdf';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
readfile($file_url);
exit();
Reference:
(1) Force Files to Download and Not Open in Browser Using Apache or PHP
(2) Force save files all browsers - not open in browser window

Related

Firefox - Selenium - Python - Download an image from URL rather than opening in Tab

Background:
I am trying to download files, among them some images, from a series of URLs.
The majority of files are downloaded as I've used the browser.helperApps.neverAsk.saveToDisk setting to included every MIME type listed in the system.
Because the site requires authentication I am using Selenium & Python to automate the login and then sequentially execute driver.get(URL) to get the files; using requests doesn't work because of the authentication.
Problem:
Some files (specifically txt, jpg & gif) open in the tab and therefore aren't downloaded.
What I need Firefox to do is open the image URL and download the file rather than open it.
Example URL for behavior - not from the actual site as it's a corporate system:
https://i.stack.imgur.com/nZBRw.png
Even with text/plain, image/jpeg and image/gif added to browser.helperApps.neverAsk.saveToDisk they still open in the tab.
The MIME types are sent correctly from the server, tested with Fiddler.
I can find no override for the behavior in Firefox, never mind with Selenium controlling it. If I could I would override the settings and build a profile to import or automate modifying the settings in some way.
firefoxProfile = webdriver.FirefoxProfile()
firefoxProfile.set_preference("browser.download.folderList",2)
firefoxProfile.set_preference("browser.download.manager.showWhenStarting",False)
firefoxProfile.set_preference("browser.download.dir",sDownloadDir)
firefoxProfile.set_preference("pdfjs.disabled",True)
firefoxProfile.set_preference("browser.helperApps.neverAsk.saveToDisk","image/bmp,image/gif,image/x-gif,image/jpeg,image/x-jpeg,image/png,image/tif,image/tiff,image/x-ms-bmp,image/x-png,image/x-portable-bitmap,text/plain")
Tried adding image/x-jpeg and image/x-gif as above because BMP files were downloading but that hasn't helped.

File is showing instead of download

When I download file, it is not downloaded and it shows in browser.
zip file is downloaded. this say server is working,
but when i try with ipa file(the extension of file is ipa), it shows content of file in browser instead of downloading.
I am using mamp.
Please help me
You may want to set a Content-Disposition header for this file - please see more information on MDN Content-Disposition. This way the server indicates that the file is an attachment and should be saved on the disk.
Content-Disposition: attachment
Content-Disposition: attachment; filename="filename.jpg"
The filename parameter is not mandatory. However, it'll suggest the name of the file.
On the other hand, if you have a HTML5 page with an anchor tag you may want to use download attribute, e.g.:
<a href="filename.jpg" download="filename.jpg">
The problem with download attribute is - it's not supported by all of the major browsers - see download attribute support. There is still a lack of support from the IE, iOS and Opera mini.

How do I return css files with response headers using a flask app running on Apache with HTTPS?

I have a flask app running on an apache HTTP server on ubuntu 14.04. Everything works great, but I'm now trying to make things secure and get HTTPS up and running. The content still renders properly when requesting the HTTP URLs, but static CSS files are not loading when changing the prefix to HTTPS.
Some useful details and previous attempts:
I have the CSS files in the usual static/css location.
This answer was helpful, and got javascript rendering properly, but using AddType for CSS isn't working for some reason.
I tried sudo a2enmod mime to make sure that Apache module was enabled, and it was.
I tried forcing the type for css (similar to what was suggested here, but with css instead of js and javascript), but that didn't work either.
I've tried adding the AddType declaration to my configuration file located in /etc/apache/sites-available/FlaskApp.conf (that's where the successful AddType text/javascript .js declaration is located), and I've also tried putting the AddType declaration in a .htaccess file located in the root directory of my FlaskApp, but both attempts were unsuccessful.
Everything loads fine when accessing the site with the http:// prefix, just not the https:// prefix. I've tried accessing it from Chrome and Firefox.
Chrome Response
Looking at the console when loading the page in Chrome is shows the following for all CSS files:
Resource interpreted as Stylesheet but transferred with MIME type application/x-gzip
Looking at the network tab, everything looks similar between the http request and the https request, except that the https request is completely missing the Response Headers section.
When attempting to load just the /static/css/styles.css file in Chrome, it attempts to download the file instead of displaying it in the browser.
Firefox Response
When attempting to load just the /static/css/styles.css file in Firefox, it loads in the browser. However, it's not ascii text but rather jumbled characters as though it's loading a binary file. Here's the console error message in Firefox:
The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
So my question is, how do I get my HTTPS/Flask/Apache/Ubuntu setup to properly return static css files so that my pages render properly?
This suggestion and this suggestion look promising, but I'm not sure how to make it so that any request that hits /static/css/*.css returns the proper css file with the "Content Type" or "mimetype" set correctly.

open pdf file through URL using uid

I work with alfresco 4.2
I want to get an image from alfresco through URL using uid
I can get the result through this link
http://localhost:8080/alfresco/service/api/node/content/workspace/SpacesStore/98996554-212 f-4846-876a-89b40999901a/test.jpg
my problem is to do the same thing but for a pdf file
with chrome I can not open the file
and firefox the file is opened in binary format
is there a way to open a pdf file through URL using the uid of alfresco file
I'd try using the download servlet. I believe the url you are using is not setting the mimetype headers correctly. This url should do the trick:
/alfresco/download/direct/workspace/SpacesStore/0000-0000-0000-0000/myfile.pdf
Possible reason could be mimetype of your pdf file is not correctly set. Normally browsers have addons avilable out of box which enable them to read pdf file correctly.
https://helpx.adobe.com/acrobat/using/display-pdf-in-browser.html
Those appliation are associated with perticular file types so whenever it detects that file type browser invoke that application to deal with it. So you can make sure your file's extension and mimetype are correct.
One more thing you can try is download that file and try to open it directly in browser.
Also, there are chances file may be corrupt. Are you able to see prview of pdf in alfresco?

Firefox doesn't understand svg on remote server

I've got a curious problem where FireFox (and IE9, I think) can display a local html file which embeds an svg, but it can't display exactly the same file when it's on a remote server. Any ideas much appreciated.
The setup is that I have a test directory which contains index.html, an svg file, and a js file. When I point any browser at index.html it correctly displays the embedded svg. However, when when I upload this test directory to a remote server, then:
1 - Opera, Safari, and Chrome correctly display the svg
2 - FireFox complains that it needs a plugin for the svg
3 - IE9 displays nothing.
Something is different about the remote setup, but I have no idea what. My suspicion is that this is an interaction of some sort with Apache (when I view index.html locally I'm not using Apache, of course - the browser is directly viewing the file).
Any ideas? Thanks.
Make sure the remote server sends the appropriate MIME type "image/svg+xml".
I run to this issue aswell on my remote server.
Adding this to .htaccess file solved my problem.
AddType image/svg+xml svg
AddType image/svg+xml svgz
For more information see SVG MIME TYPE