Send project id from IPFS Infura Java Android

In this tutorial show how in the following code how to connect to the infura project using android devices, but today this code shows the error “project id is required”

Is there a way to send credentials about projectid and keysecret with the IPFS Library or need use something like HttpUrlConnection?

/Implementing IPFS with Infura API's
MultiAddress IPFS_INFURA_URL = new MultiAddress("/dnsaddr/ipfs.infura.io/tcp/5001/https");

//Creating an IPFS client:
IPFS ipfsClient;

//Better to separate declaration and definition as connecting to the client requires a network call
//In Android, a network call cannot be performed on the main thread
//Doing so produces a Android.OS.NetworkOnMainThreadException

new Thread(new Runnable() {
    @Override
    public void run() {
        ipfsClient = new IPFS(IPFS_INFURA_URL);
    }
}).start();

Hi @gabriel, you could certainly not use a nice wrapper like
https://github.com/ipfs-shipyard/java-ipfs-http-client/
and fall back to HttpUrlConnection. Alternatively you could rise an issue on the repo or even make the change yourself and contribute a pull request.

It seems to me the change would be to add an “addHeader()” method, store the header away in the class (probably an array for full generality), and have the configureConnection() method take the new header(s) and send them when the connection is created.

Warm regards,
Chris | Infura | ConsenSys

Hi @chris.paterson and how i can do this?

Sorry if I didn’t understand correctly, English is not my primary language and I still need to improve it

Hi @gabriel, no problem at all.

I was referring to forking the ipfs-http-client github repository, making the code changes to it it add the ability to include an authorization header in each request it sends, as per:
https://docs.infura.io/infura/networks/ipfs/how-to/authenticate-requests
Then you would have an enhanced version of the code that solves your problem.

You could then take the extra step of providing your version back to the repository as a pull request, for everyone to use, once the maintainers merge it.

So, no, there’s no addHeader method yet, it would need to be added. If you feel you don’t have the skills yet to add it yourself, then open an issue on the repository and hopefully someone will eventually make the change.

Warm regards,
Chris | Infura | ConsenSys

hi @chris.paterson you idea works!!! thank u so much

1 Like