1

我有一个向我发送文件流的 api 调用。我得到流并将其作为 uInt8Array 输出。

我使用这个 html5 示例:

http://www.html5rocks.com/en/tutorials/file/xhr2/

我知道文件名和类型是什么,如何将此数组数据放入“文件”并提供给用户下载?

xhr = new XMLHttpRequest()
xhr.open "GET", "#{window.API_URL}/transfer/123/2134/#{program_id}", true
xhr.responseType = "arraybuffer"
xhr.onloadstart = (e) ->
    # downloading file notify on footer
xhr.onprogress = (e) ->
    # show progress and size of file.
    console.log "#{Math.round(e.loaded/e.total)*100}% completed"
xhr.onload = (e) ->
    uInt8Array = new Uint8Array(@response)

xhr.send()
4

1 回答 1

1

试试这种方法(适用于 IE10+、FF、Chrome):

var blob = new Blob([uInt8Array], {type: contentType });

并参考答案

于 2015-02-04T07:37:35.847 回答