1

I have a api call that sends me the a stream of a file. I get the stream and put it out as an uInt8Array.

Im using this html5 example:

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

I know what the file name and type is, how do I put this array data into a "file" and give that to the user to download?

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()
Harry
  • 13,091
  • 29
  • 107
  • 167

1 Answers1

1

Try this approach (works in IE10+, FF, Chrome):

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

and refer to the answer

Community
  • 1
  • 1