javascript字节数组来制作下载链接

时间:2014-11-24 23:20:28

标签: javascript download bytearray

我有一个名为file_test的字节数组,我只想下载字节数据。

当我下载它。它看起来像这样。

http://i.stack.imgur.com/Gxm83.png

我该如何解决?

function download(strData, strFileName, strMimeType) {
    var D = document,
        A = arguments,
        a = D.createElement("a"),
        d = A[0],
        n = A[1],
        t = A[2];

    //build download link:
    a.href = "data:" + strMimeType + "," + strData;

    if ('download' in a) {
        a.setAttribute("download", n);
        a.innerHTML = "downloading...";
        D.body.appendChild(a);
        setTimeout(function() {
            var e = D.createEvent("MouseEvents");
            e.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            a.dispatchEvent(e);
            D.body.removeChild(a);
        }, 66);
        return true;
    };
}

file_test// file_test = [255],[216],[255],[224],[0],[16],[74],[70],[73], more
download(file_test, 'filename.jpg', 'image/jpeg');

0 个答案:

没有答案