在JavaScript中从DataURL下载文件 [英] Downloading file from DataURL in JavaScript

查看:125
本文介绍了在JavaScript中从DataURL下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们从DataURL获取这个字符串,将其作为文件下载的最佳方法是什么?

From this string we get from DataURL, what's the best way to download this as a file?

到目前为止,我得到的是使用基本的 window.open(myDataURL); ,但我无法以这种方式更改文件名。

So far what I got was using a basic window.open("myDataURL");, but I'm not able to change the file name in this way.

window.open('data:application/msword;base64,0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAA
             PgADAP7/CQAGAAAAAAAAAAAAAAACAAAANQAAAAAAA
             AAAEAAANwAAAAIAAAD+////AAAAADQAAABsAA/',
             '_blank','height=300,width=400');

我想知道是否有办法正确处理这些数据。

I was wondering if there's any way to handle this data properly.

推荐答案

您可以将 download 属性添加到锚元素中。
样本:

you can add a download attribute to the anchor element. sample:

<a download="abcd.zip" href="data:application/stream;base64,MIIDhTCCAvKg........">download</a>

这篇关于在JavaScript中从DataURL下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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