数据中下载文件的文件名:Application / octet-stream; [英] Filename of downloaded file in data:Application/octet-stream;
问题描述
< input type =button$ 我试图使用数据uri以下列方式下载文件: b $ b onclick =window.location.href ='data:Application / octet-stream; content-disposition:attachment; filename = file.txt,$ {details}'
value =Download/> gt ;
问题是下载的文件总是被命名为'Unknown',无论我尝试使用
文件名。这是给文件起一个名字的正确方法吗?或者其他的东西需要被
完成?
这是解决方案,您只需添加<$ c
code $ a pre> < a href =data:application / csv; charset = utf-8,Col1%2CCol2%2CCol3%0AVal1%2CVal2%2CVal3%0AVal11%2CVal22%2CVal33%0AVal111%2CVal222% 2CVal333
download =somedata.csv>示例< / a>
另一个解决方案是使用JQuery / Javascript
I am trying to download a file using data uri in following manner:
<input type="button"
onclick="window.location.href='data:Application/octet-stream;content-disposition:attachment;filename=file.txt,${details}'"
value="Download"/>
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 be done ?
Here's the solution, you just have to add a download
attribute to anchor tag
a
with desired name
<a href="data:application/csv;charset=utf-8,Col1%2CCol2%2CCol3%0AVal1%2CVal2%2CVal3%0AVal11%2CVal22%2CVal33%0AVal111%2CVal222%2CVal333"
download="somedata.csv">Example</a>
Another solution is to use JQuery/Javascript
这篇关于数据中下载文件的文件名:Application / octet-stream;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!