How to add a file with js-ipfs in the browser using Buffer and/or Stream #257
Comments
|
Also once the file has been uploaded, how would I go about retrieving the multihash for later use? |
|
Hi @fullmetal1, the short answer to your question is: Did you get the chance to check js-ipfs examples, especially the
If you are adding a single file, you can leave the
Both Buffer and Streams have polyfills for Browser land, see: Any browser bundler (WebPack, Browserify and so on) will shim them for you. Hope this helped :) Let me know! |
|
It is worth mentioning that const Buffer = window.IpfsApi().Buffer |
|
Right! Same for https://github.com/ipfs/js-ipfs/blob/master/src/core/index.js#L54-L62 |
|
thanks. I managed to convert my ArrayBuffer into a Buffer with ipfs.types.Buffer(content), and now adding files is working well. I'd also like to note that I'm not likely going to be using a browser bundler. Part of the reason I'm making my program is to be as lightweight and simple as possible (ie., user loads the page, and they can get and add files as they like). At any rate I'm again making progress. Thanks for the help |
fullmetal1 commentedMay 15, 2017
•
edited
The current documents (https://github.com/ipfs/interface-ipfs-core/tree/master/API/files#add) mention a data array, with two elements. A 'path', and 'content'. I want to know what the purpose of feeding a path to ipfs is when it has the file contents in the content object. I also want to know how I can use ipfs.files.add without the need for Node.js, since both Buffer and readable streams (AFAIK) are Node.js object types.
More to the point, I have a function in a webapp (client side, only html + js) with access to an ArrayBuffer variable that contains a files contents, as well as the filename for the file. What should I do to make ipfs.files.add work with what I have?
The text was updated successfully, but these errors were encountered: