问题
Is it possible for webodf to read a odf / odt file from its bytes? instead of an url?
Currently using:
var odfelement = document.getElementById("odf");
var odfcanvas = new odf.OdfCanvas(odfelement);
odfcanvas.load("url/to/file.odt");
and would like something like
odfcanvas.loadFromBytes(bytes);
回答1:
Yes, It is possible to read an odt file from byte Array and then load it in webodf editor.
To do so ,you will have to use javascript blob objects to construct a file from a byte array(desired file in bytes format).
Then you can get a temporary url for that blob object which is very similar to a file itself.The 'url' is temporary url created and stored in browser.
Once you have the url for your file ( bytes => blob => getUrl ) then you can easily load the file in your webodf editor using 'openDocumentFromUrl' function.
var file = new Blob([data], {type: mimeType});
// data => your bytes file
// mimeType => the mimetype of file(odt : application/vnd.oasis.opendocument.text)
var myUrl= URL.createObjectURL(file);
// get the temorary url from blob object.
editor.openDocumentFromUrl(myUrl, function(){});
// editor is the active webodf context object which you get when webodf context is created
回答2:
We are using WebAPIs to push out the file stream. Seems you could setup a shim service to much the same? Else there might be some info to glean form the local editor (as it must do an upload of some form)?
Which I could help more, but I'm new to WebODF myself and thus far it's been a bit... obtuse ;)
来源:https://stackoverflow.com/questions/21584759/webodf-display-odf-from-bytes