数据中下载文件的文件名:Application / octet-stream; [英] Filename of downloaded file in data:Application/octet-stream;

查看:1633
本文介绍了数据中下载文件的文件名: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

Anchor's Download Property

这篇关于数据中下载文件的文件名:Application / octet-stream;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆