0

I am making a POST request to my IPFS node. I am trying to log the results in console. My response is in JSON format. How do I do this? Thanks.

{Name: "<Random Value here>",…}
Hash: "<Random Value here>"
Name: "<Random Value here>"
Size: "<Random Value here>"
function upload() {
  document.getElementById("loading").innerHTML = `<p>Uploading...</p>`
  const reader = new FileReader();

  reader.onloadend = function() {
    const ipfs = window.IpfsApi('<IP>', 80) // Connect to IPFS
    const buf = buffer.Buffer(reader.result) // Convert data into buffer
    ipfs.files.add(buf, (err, result) => { // Upload buffer to IPFS
      if (err) {
        console.error(err)
        return
      } 
      console.log([RESULTS HERE])
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

0

It looks like you don't get the result logged because there is no result. Something went wrong either during the API call or during the setup.

Which library does window.IpfsApi come from? (Looks like an outdated version of ipfs-http-client, but I'm not sure.)

Does your IPFS node actually expose its API at the address and port that you expect? You can check that by sending a request using curl.

Is err printed out in the console? If yes, it might provide information about the request failure. If no, the request probably wasn't even sent due to an error that happened before the API call. Make sure that ipfs and buf are defined, and ipfs.files.add is invoked correctly.

foo
  • 106
  • 2