Skip to content

ipfs.add() with FileWrapper should not URL-encode filenames. #76

Closed
@bwkimmel

Description

@bwkimmel

If I try to add a file whose name contains a character affected by URLEncoder.encode, the file name in IPFS ends up as the encoded version of the original. To reproduce:

$ mkdir /tmp/foo
$ touch '/tmp/foo/bar$baz.txt'

Run the following program:

import java.io.File;
import java.io.IOException;
import java.util.List;

import io.ipfs.api.IPFS;
import io.ipfs.api.MerkleNode;
import io.ipfs.api.NamedStreamable;
import io.ipfs.multiaddr.MultiAddress;

public class Test {
  public static void main(String... args) throws IOException {
    IPFS ipfs = new IPFS(new MultiAddress("/ip4/127.0.0.1/tcp/5001"));
    NamedStreamable dir = new NamedStreamable.FileWrapper(new File("/tmp/foo"));
    List<MerkleNode> nodes = ipfs.add(dir);
    System.out.println("/ipfs/" + nodes.get(nodes.size() - 1).hash.toBase58());
  }
}

This prints out: /ipfs/QmSuq7496UJ3b5fZJWWnZknWxtfazGDQ3Gw5gfG1YNfvdd

$ ipfs ls /ipfs/QmSuq7496UJ3b5fZJWWnZknWxtfazGDQ3Gw5gfG1YNfvdd
QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH 6 bar%24baz.txt

Compare this with the behavior using ipfs add -r:

$ ipfs add -r /tmp/foo
added QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH foo/bar$baz.txt
added QmYYohh3cVpiMCwsr4hLpRdN6qmsKrrPDdNJMYVqekk2cq foo
$ ipfs ls /ipfs/QmYYohh3cVpiMCwsr4hLpRdN6qmsKrrPDdNJMYVqekk2cq
QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH 6 bar$baz.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions