kennethjiang/js-file-download

get a broken file

Closed this issue · 7 comments

"js-file-download": "^0.4.8",

`
import download from "js-file-download";

download('http://lixing-develop.oss-cn-hangzhou.aliyuncs.com/large_file/1573546365135.png','你')
`
where fix it??

same problem

same problem in 0.4.12

it works

import Axios from axios;

function download(url: string, filename: string) {
  Axios.get(url, {
    responseType: 'blob',
  }).then(res => {
    fileDownload(res.data, filename);
  });
}

@zhangminggeek is 100% correct. Binary files should be in Blob format 🚀

@zhangminggeek responseType 'blob' works perfectly. You saved my life!

This also just saved my life. Thank you kindly.

Thank you @zhangminggeek for the code snippet and @ignatvilesov for the explaination.

I updated the README to hopefully help others from avoiding this gotcha.