Unable to get a file using the js http api

I’m trying to retrive an audio file from my ipfs repo using the javascript implementation of the http api. I’m using files.get, passing the path to my hash but am never returned anything. given the code below, can you see anything i’m doing wrong?

const NodeID3 = require('node-id3'),
      ipfsAPI = require('ipfs-api')

const ipfs = ipfsAPI({
  host: "",
  port: 5001,
  protocol: 'http'

let self = {

  getId3Data : track => {
    ipfs.files.get(`/ipfs/${track.audioHash}`, (err, files) => {
      if (err) {
        return false;

      // files.forEach((file) => {
      //   console.log(file.path)
      //   console.log(file.content.toString('utf8'))
      // })

      // let buffer = new Buffer(file.content)
      // let tags = NodeID3.read(buffer)
      // console.log(file, buffer, tags);


as you can see i’ve tried a few things, files.forEach gives me files.forEach is not a function and just reading .path and .content are undefined… i tried like this because i am only ever working with one file, i know the docs say it’s suppose to come back as an array. This is what files comes back as in the console.

ObjectsStreams {
   ReadableState {
     objectMode: true,
     highWaterMark: 16,
     buffer: BufferList { head: null, tail: null, length: 0 },
     length: 0,
     pipes: null,
     pipesCount: 0,
     flowing: null,
     ended: false,
     endEmitted: false,
     reading: false,
     sync: true,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     destroyed: false,
     defaultEncoding: 'utf8',
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null },
  readable: true,
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined }

if anybody could point me in the right direction that would be great!

1 Like

checklist to debug your code :


thanks for your reply, in the same order:

  • My app uploads and reads files (by url, not buffer) for creating and displaying the audio/images, and when i set it up i added the CORS related headers so that should be fine.

  • audioHash is correct, it’s read from the database, an entry which is created on successful add to the ipfs repo.

  • The last block of code i quoted is what files comes back as. I’m not totally familiar with reading from buffers, but the length is 0, and there seems to be a lot of null’s. So it seems like it’s failing.

I’m seeing exactly the same problem.

@invisibled, were you able to find a solution back then?

For reference, the IPFS hash I’m looking at is QmaG6o1vkjMG3WRdo8kTRfdLydfhDPmqDnNutCziP2BNfv.


In the end I didn’t need to get hashes this way. I keep track of them in a database with the other data and simply link to my local node to access them. One thing I didn’t understand when I posted this was if you upload multiple files together they are uploaded under a parent hash, and each have there own hashes. This could have been my issue, but I’m not sure.