0

I have the following file uploaded to an Express.js API, using Multer

[ { fieldname: 'file',
    originalname: 'file.pdf',
    encoding: '7bit',
    mimetype: 'application/pdf',
    destination: 'temp/',
    filename: 'b9e10b5ecce35483ff38c0e83b41a9f5',
    path: 'temp/b9e10b5ecce35483ff38c0e83b41a9f5',
    size: 456904 } ]

I passed it to the IPFS protocol with the ipfs.add() using the following function

ipfs.add({
  path: listItem.path,
  content: fileBuffer,
}, (err, file) => {
  if (err) reject(err);
  console.log(file)
});

Which in the console.log() returns the following output

[ { path: 'temp/b9e10b5ecce35483ff38c0e83b41a9f5',
    hash: 'QmUNLLsPACC***',
    size: 4 },
  { path: 'temp',
    hash: 'QmfQjRQnQkV***',
    size: 82 } ]

My question is, why the second item appears if its supposed to be just adding the PDF file, and why it has my temp folder as a path, it is uploading all inside it?

1 Answers1

0

That is the automatically-created directory to hold the file. The path you are passing has temp/ at the start, so that directory is created.

Taken directly from the documentation on .add():

Note that intermediate directories in file paths will be automatically created and returned in the response along with files:

Conspicuous Compiler
  • 6,403
  • 1
  • 40
  • 52