Ipfs.add() or get() is not setting correct filename or extension type

I can add a file and get a successful response like:

  Name: 'Screenshot 2021-10-14 160031.png',
  Hash: 'QmXk1HX751jRWwj9Cv8Bt8fo9cahwrn7F7uY682eFuBWyT',
  Size: '317573'

But when I query this hash URL:

The browser downloads as “get” with wrong filename and no extension.

Do I have to use the Content-Disposition header to specify the filename too? I set the FormData filename.


Javascript NodeJS code is like this:

const formData = new FormData();
formData.append("file", file.buffer, file.originalname);
const ipfsResponse = await fetch(infuraIpfs.endpoint + "/api/v0/add", {
        method: "POST",
        headers: {
               Authorization: `${infuraIpfs.projectId}:${infuraIpfs.projectSecret}`,
               ContentType: "multipart/form-data",
        body: formData

hi @ChristopherTrimboli and welcome to Infura community !
If you want to preserve the filename you need to wrap it with a directory, eg pass wrap-with-directory argument, see https://infura.io/docs/ipfs#tag/add

Also some details here about this: https://discuss.ipfs.io/t/what-does-arg-wrap-with-directory-from-add-function-do/1842

I hope it helps !


1 Like