Changed Title from “Cannot download data URIs” to “Cannot download data URIs” lou c. Jul 12, 2016 2016-07-12T16:31:11.167Z any updates on this? It still seems to be an issue. PDF attachments with Content-Type: application/octet-stream are handled bad. I've written a download Servlet to return a file based. Download a file through an HTTP Get in. (mimetype!= null)? Mimetype: 'application/octet-stream').
I am trying to download a file using data uri in following manner:
The problem is that the downloaded file is always named 'Unknown', whatever I try to use as filename. Is this the correct way to give the file a name ? or something else needs to bedone ?
Ashraf Bashir5 Answers
Here's the solution, you just have to add a download
attribute to anchor taga
with desired name
Another solution is to use JQuery/Javascript
Ashraf BashirAshraf BashirOn Safari, you might want to use this, and instruct the user to ⌘-S the file:
Otherwise, this uses Filesaver.js, but works ok:
Note: There is some AngularJS in the code above, but it should be easy to factor out...
For those that are using other libraries like angularjs or backbone, you can try something like this.
$('a.download').attr('href', 'data:application/csv;charset=utf-8,'+$scope.data);
RickRickI had the same issue and finally I solved in all browsers serving the CSV file in the server-side:
Aral RocaAral RocaFor anybody looking for a client-side solution using Javascript only, here is mine, working on any browser except IE 10 and lower (and Edge...why?!):
Not the answer you're looking for? Browse other questions tagged htmldata-uri or ask your own question.
Did your computer fail to open an OCTET-STREAM file? We explain what OCTET-STREAM files are and recommend software that we know can open or convert your OCTET-STREAM files.What is an OCTET-STREAM file?
The OCTET-STREAM format is used for file attachments on the Web with an unknown file type. These .octet-stream files are arbitrary binary data files that may be in any multimedia format. The OCTET-STREAM format was developed for Web browsers to understand that the file attachment is in an unknown file type, which also allows the user to choose to download and save the attached file in any file format that the user wants.In other instances, the OCTET-STREAM file format is used to inform the user that the attached file may be saved in a recommended file format. This also allows the Web browser to enable the user to know the recommended file format for the attached .octet-stream file.These OCTET-STREAM files may be opened by renaming the extension of the attached file to a specific file extension, and then by using an application with support for opening such files. For example, an .octet-stream file may be renamed to a .txt file (if it is indeed a .txt file), and Notepad may then be used to open the file. This means the user needs to know the file type of the attached .octet-stream file before renaming the file in the correct file extension.
Software that will open, convert or fix OCTET-STREAM files
Unfortunately we have not received enough suggestions for software that can open OCTET-STREAM files yet.
Try a universal file viewer
Since we do not have any programs listed that we have verified can open OCTET-STREAM files, we suggest that you try a universal file viewer like Free File Viewer. It can open over 200 different types of files - and very likely yours too! Download Free File Viewer.
Data Application Octet Stream
About File Extension OCTET-STREAM
Application/octet-stream Firefox
File.org aims to be the go-to resource for file type- and related software information. We spend countless hours researching various file formats and software that can open, convert, create or otherwise work with those files.
Application Octet Stream Firefox
If you have additional information about the OCTET-STREAM file format or software that uses files with the OCTET-STREAM suffix, please do get in touch - we would love hearing from you.