Reputation: 511
In a Windows Runtime Application, I have a javascript File object created from a Javascript Blob object and it's respective mime type.
The end goal is to open this file using the default windows application (or prompt the user to choose one). So PDF's would be opened by Adobe, ect.
At the moment, I am:
Is there any way to eliminate any of these steps? It seems redundant to save a file and open it back up when it feels like I could just "open" the file in the first place, but I don't see any documentation from Microsoft about how to just open a javascript file.
Upvotes: 0
Views: 76
Reputation: 511
For those in the future that stumble across this, there appears to be no way to skip the write step, so here is the code to save and open a blob file given a binary blob (blob) and proper file name (fileName)
var reader = new FileReader();
var blobAsArrayBuffer;
reader.onloadend = function () {
blobAsArrayBuffer = reader.result;
var folder = Windows.Storage.ApplicationData.current.temporaryFolder;
var storageFile = folder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.replaceExisting).then(
function (file) {
var u8array = Uint8Array(blobAsArrayBuffer);
Windows.Storage.FileIO.writeBytesAsync(file, u8array);
Windows.System.Launcher.launchFileAsync(file);
});
};
reader.readAsArrayBuffer(blob);
Upvotes: 1