How to keep orginal file name when store it on IPFS?

I notice that IPFSS doesn’t maintain file name on the files upload to ipfs.
For example:
https://ipfs.io/ipfs/QmUrNv5yofTVJcCZSsWM7YBd4ppzvpLDx9a6iVwp3Tp29b
this file orginal name is: eula.1028.txt
But when i download it from IPFS network it doesn’t downloaded with the orginal file name, it just append hash to the name.
How to make file downloaded with it is own name.
Thanks.

When adding the file to IPFS, you can preserve the filename by wrapping it with a directory using the -w option.

For example, ipfs add -w eula.1028.txt would result in a directory containing the file with the filename preserved.

@leerspace , Thanks for reply.
But how to do this when we add a folder with 100s of file?

Just add a folder with files in it instead of 100 files. If You add folder all filenames are preserved

1 Like

@adamskrodzki , Thanks adam.
I know i can add the folder instead of the files and it will keep the files name.
But all my files on that folders will be exposed to every one by browsing the parent folder. While i need to share each file alone using it is own hash.
And if i resolve each file on that folder alone and sharing it with it own hash , then i will come back to the first problem the orginal file name will override with hash name.

If you can’t add the parent folder and each file has to be added separately, then you can do this on linux using a simple one-liner.

find path/to/folder -maxdepth 1 -type f -exec ipfs add -w -Q --pin=false {} \;

edit: you can remove the --pin=false part if you want to keep the default behavior to pin content after adding.

edit 2: adding the -q option to only output the final hash for each directory-wrapped file

edit 3: changing the -q to a -Q

2 Likes

@leerspace , Thanks.
This is a perfect solution .
If i make it like this:
find path/to/folder -maxdepth 1 -type f -exec ipfs add -w -q {} ; 0 2>&1 | tee /tmp/fileshash.txt
The files will be pinned and result will be safed on fileshash.txt?
Correct?

I made a mistake in my previous post; the -q should instead be a -Q to limit it only to the final hash for each directory-wrapped file. The former will spit out the hash for both the file and the parent directory.

That doesn’t work for me (I don’t know what 0 2>&1 is supposed to do), but this does.

find path/to/folder -maxdepth 1 -type f -exec ipfs add -w -Q {} 2>&1 \; | tee /tmp/filehash.txt

If you want to write out the filename and the parent hash on each line separated by a tab, you could also do something like this.

find path/to/folder -maxdepth 1 -type f -exec sh -c "printf {}; printf '\t'; ipfs add --pin=false -w -Q {} 2>&1" \; | tee /tmp/filehash.txt
1 Like

Sorry , it is a typo. I mean
2>&1
Your solution work perfectly , Thank you very much for your help. You safe my day.
Regards.

1 Like