So I'm using the library on browser-side without nodeJS.
In the docs the method document.createImage() requires a buffer. I'm using a library to implement the nodeJS buffer functionality in the browser but I honestly have no clue about how to proceed without having to implement fileSystem functionality.
I'd like to use an URL to load the image.
Thanks for any help!
Buffer is only supported in NodeJS, there is no such concept as buffer in the browser world!
Fortunately, createImage() can also take in a base64 string or a Uint8Array or ArrayBuffer, which are in the browser world:
https://github.com/dolanmiu/docx/blob/master/src/file/file.ts#L139
Thanks! Also, may I ask why can't images be inserted directly? I'm not very familiar with nodeJS environment.
Images cant be inserted directly like a file path? C:\cat.png?
It used to be like that, but then it wouldn't work for browsers. Can't access C drive on the browser
And what about URLs? (in the browser environment)
I wanted that de-coupling from the implementation
I wanted docx to not care about how/where/when the image was gotten from. It can be from NodeJS buffers, or through Angular's this.http.get. All docx needed to know was the data.
It's the same reason why the packers are the way they are today
Makes sense. Thanks!
Most helpful comment
Bufferis only supported in NodeJS, there is no such concept as buffer in the browser world!Fortunately,
createImage()can also take in abase64 stringor aUint8ArrayorArrayBuffer, which are in the browser world:https://github.com/dolanmiu/docx/blob/master/src/file/file.ts#L139