I have a download button on my page that looks like this:
<a download="test.jpg" href="data:application/octet-stream;base64,/9j/4AAQSkZ...">Download</a>
The href
attribute is populated by JavaScript, and on my test server it functions exactly as I'd expect it to: it prompts a 'Save As' dialogue box with the filename "test.jpg".
However, when I use the exact same code on a different, live server, the filename is dropped.
Any ideas what could be causing this difference in behaviour across the two servers?
答案 0 :(得分:1)
这是保存非现场下载时应用的安全措施。由于prototcols不匹配(数据vs http),它被认为是一个不同的网站,默认名称适用。使用URL.createObjectURL而不是base64来提供下载的href。您可以获得dataURL to Blob routine in my downlod.js library,然后将Blob提供给createObjectURL()。