1

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);
djv
  • 15,168
  • 7
  • 48
  • 72
cipriota
  • 11
  • 3

2 Answers2

2

Yes, It is possible to read an odt file from byte Array and then load it in webodf editor.

  1. To do so ,you will have to use javascript blob objects to construct a file from a byte array(desired file in bytes format).

  2. 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.

  3. 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
damitj07
  • 2,689
  • 1
  • 21
  • 40
0

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 ;)

Campbeln
  • 2,880
  • 3
  • 33
  • 33