开发者

How to download file given raw data?

开发者 https://www.devze.com 2023-03-31 06:13 出处:网络
I have a web service call that returns {\"data\": BINARYDATA}. How can I pop up a dialog to download the file based on only those binary data? It could be a file of any type. I\'m probably looking for

I have a web service call that returns {"data": BINARYDATA}. How can I pop up a dialog to download the file based on only those binary data? It could be a file of any type. I'm probably looking for a Javascript function, or maybe a browser-specific function? Thanks.

EDIT: I am checking to s开发者_运维知识库ee how the data are encoded. Will update soon with that (important) information.

EDIT 2: I investigated Using HTML5/Javascript to generate and save a file . Thank you for the referral. My main problem with the dataURI method is that my files are larger than 256kB


Resolved:

The answer is that this is not a good client-side task (particularly when dealing with large files). It's much better to change the server-side code to return the appropriate HTTP response (with headers) instead of JSON.

Thanks everyone for your help in the comments.

0

精彩评论

暂无评论...
验证码 换一张
取 消