IPFS gives same CID for fileObjects

Hello guys,
IPFS keeps giving me the same CID, am I doing something wrong? I am using Infura’s IPFS.

for await (const result of ipfs.add(req.files)) {
ipfsResult.push(result)
}
console.log(ipfsResult)

Response
{ path:
‘uploads\docs\5ea035c47d671a44c88ebd49\file-2020041799324.pdf’,
cid: CID(QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn),
size: 4 }
{ path:
‘uploads\docs\5ea035c47d671a44c88ebd49\file-2020041799824.pdf’,
cid: CID(QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn),
size: 4 }
{ path:
‘uploads\docs\5ea035c47d671a44c88ebd49\file-202004185424.docx’,
cid: CID(QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn),
size: 4 }

Hello,

The CID QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn seems to me to be the signature of an empty file.

Are you sure of the content of req.files ? Is it [‘uploads\docs\5ea035c47d671a44c88ebd49\file-2020041799324.pdf’, ‘uploads\docs\5ea035c47d671a44c88ebd49\file-2020041799824.pdf’, …] ?

If the array is a list of “{path:‘path’}” without the content field it may explain.

Nicolas

Yes, it’s an array with file path. So I will need to add the file content to the array.
Do I need to buffer the file to get the content. Also, can I leave out the path and just send the content in the array to ipfs.

Thanks.

If I understand you well, I think you just have to pass an array like this

[
  "uploads\docs\5ea035c47d671a44c88ebd49\file-2020041799324.pdf", 
  "uploads\docs\5ea035c47d671a44c88ebd49\file-202004185424.docx", 
  …
]

Thank you very much. I should have come here earlier instead of wasting my time trying to solve it almost all day. Works now.

1 Like