Download link via http/https

Hi everyone, i have a question, i use IPFS with js-ipfs in my webapp, to add file to infura.

After that i put a link in my webapp using the hash like this:

https://ipfs.infura.io/hash

It work well for let’s say images, pdf or so but if the file is something that cannot be read from the browser, like a psd for example, it open the download window and i seem to download the hash, not the file.

I guess this is not the proper way to download a file? or it is not possible via https link ?

Thank you in advance

You are probably downloading the file which is renamed to the hash because that’s all that is known about it. If you wrap it in a folder (there’s an option for that), you should be able to keep the filename and reference it like <hash>/filename and the download will keep the filename.

Thank you for your reply i will check that.

Hello,

I might be missing something but trying to add file keeping file name i do the following:

const files = [{ path: "/"+file.name, content: file }];
ipfs.add(files, { pin: true })

then i get this result in console when done:

ipfs

Seem that all is good but then i can only access file from cid on gateways, i was expecting cid/path, isn’t it suppose to be like that?

Just putting the path on the file name doesn’t do it. The add itself must be either the directory path only (in which case I believe all files within the directory tree will be added) or the “wrap-with-directory” flag must be specified as documented at https://docs.ipfs.io/reference/http/api/#api-v0-add. Otherwise I believe the file will only have a hash to the content and not a hash to a file structure that carries the name for future reference prefixed by the hash.

Thanks a lot for the replied, i just tried using wrapWithDirectory options as per ipfs-http-client doc: ipfs.add

So my code is now:

const files = [{ path: "/"+file.name, content: file }];
ipfs.add(files, { pin: true, wrapWithDirectory: true })

But same result so far :confused:

My bad it’s working, thanks a lot :slight_smile: