Skip to content Skip to sidebar Skip to footer

Angularjs Dynamic Download From Response

I have written a directive based on Scott's answer. You'd use it like so:

So essentially the generic alias created to encapsulate saveBlob functionality, which should be permissible, prevents msSaveBlob from working as expected:

var saveBlob = navigator.msSaveBlob || navigator.webkitSaveBlob || navigator.mozSaveBlob || navigator.saveBlob;

Workaround:

So the work around is to test for msSaveBlob separately.

if(navigator.msSaveBlob)
    navigator.msSaveBlob(blob, filename);
else {
    // Try using other saveBlob implementations, if availablevar saveBlob = navigator.webkitSaveBlob || navigator.mozSaveBlob || navigator.saveBlob;
    if(saveBlob === undefined) throw"Not supported";
    saveBlob(blob, filename);
}

tl;dr

So the msSaveBlob method works, as long as you don't alias the function. Perhaps it's a security precaution - but then perhaps a security exception would have been more appropriate, though I think it is most likely a flaw, considering the source. :)

Post a Comment for "Angularjs Dynamic Download From Response"