0

i have a Problem with IPFS and Java. There are many Examples in the Internet but they aren't work anymore, cause GET is not longer supportet by IPFS. The Dependencies are included in pom.xml. So here is the Problem. I tried with POST Rest, but still this Error. Do you know how to fix this with POST in Java?

IPFS ipfs = new IPFS("/ip4/127.0.0.1/tcp/5001");

@POST
@Path("/file2IPFS")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response test(@FormDataParam("file") InputStream uploadInputStream) throws IOException {
    //create File from Inputstream is normally included but for Example with Hello.txt


    ipfs.refs.local();

    NamedStreamable.FileWrapper file = new NamedStreamable.FileWrapper(new File("hello.txt"));
    MerkleNode addResult = ipfs.add(file).get(0);
    
    
    return Response.status(200).entity("Passt").build();
}

This is the Code Snipptet. This Method is part of an Rest-Webservice.

java.lang.RuntimeException: IOException contacting IPFS daemon.
Trailer: null 405 - Method Not Allowed
at io.ipfs.api.IPFS.get(IPFS.java:592)
at io.ipfs.api.IPFS.retrieve(IPFS.java:571)
at io.ipfs.api.IPFS.retrieveAndParse(IPFS.java:553)
at io.ipfs.api.IPFS.version(IPFS.java:501)
at io.ipfs.api.IPFS.<init>(IPFS.java:61)
at io.ipfs.api.IPFS.<init>(IPFS.java:52)
at io.ipfs.api.IPFS.<init>(IPFS.java:48)
Simon
  • 3
  • 2

2 Answers2

0

You should use the older IPFS version.

0

This problem is caused by a breaking change in the HTTP interface of the IPFS daemon. Since version 0.5.0, all the endpoints accept only POST requests.

UPDATE: A new version of java-ipfs-http-client has been released on 2020-08-03. It supports IPFS 0.5.x and 0.6.x, thus all the information below has become irrelevant. I'm keeping it just for historical purposes.


You seem to be using the java-ipfs-http-client library as a wrapper above the bare HTTP interface. Sadly, that library hasn't been updated in quite some time, and its latest release isn't compatible with IPFS 0.5.0 and later.

It seems that the author of java-ipfs-http-client has lost interest in maintaining it. However, he has incorporated the IPFS wrapper code into another project of his, Peergos. That version is actually compatible with the fresher versions of IPFS, and it also has a couple of the critical bugs fixed that are present in the dependencies the standalone library.

The quick and easy solution to the problem is, as @hau-phvn suggested, downgrading your IPFS daemon to version 0.4.23.

If you need to use an up-to-date IPFS server, try using Peergos as a dependency (or try snipping just the relevant pieces, because the whole project contains a lot of other functionality that you probably don't need). Also you may try your luck with some of the recent forks.

foo
  • 106
  • 2