Hello @gabriel , can you try to generate the needed base64 string from the CLI for example and then pass it to your conn.addRequestProperty?
You can use the following to generate the string: echo -n "ProjectID:ProjectSecret" | base64 -w 0
Then use it as such in conn.addRequestProperty(“Authorization”, “Basic base64string”).
Found this stackoverflow resource with several possible answers on how to create basic auth with java. Maybe it helps.
Also can you kindly share the full error you are receiving?
Hey @gabriel , I have managed to successfully connect to Infura IPFS using one of the examples in the stack overflow link I shared in my earlier reply. Java is not my strongest point, but please see the below code snippet example for an HttpBasicAuth class:
@radu stranger, using exacly url https://ipfs.infura.io:5001/api/v0/cat?arg=QmYt9ypyGsR1BKdaCGPdwdBgAiuXK5AYN2bGSNZov7YXuk and using my PROJECT ID and API KEY SECRET, continuos send the same error
I need install a something in my computer or a specific url?
In the really, what means QmYt9ypyGsR1BKdaCGPdwdBgAiuXK5AYN2bGSNZov7YXuk
Hey. let’s try to troubleshoot this within a support ticket. Please raise one here Contact Us | Infura, by selecting Customer Support from the dropdown, also please specify the email associated with your Infura account.
QmYt9ypyGsR1BKdaCGPdwdBgAiuXK5AYN2bGSNZov7YXuk is the Content Identifier (CID) of an object stored in IPFS.
I can send you some introductory material on IPFS and how you can make use of of your Infura IPFS project.
Hey @gabriel , all requests sent to the Infura Ipfs api need to be authenticated, but in order to upload a file you will need to use the POST method. By using GET you will receive a 405 method not allowed error, as get is not supported.
So basically in the same call you could authenticate your project and upload a file.
But a 401 error code means that you are not passing the authentication header correctly. Have you tried the code example I shared and just replacing the Project ID and Project Secret with yours?
From what I see there’s little support in the community for the java ipfs http client, as opposed to the javascript ipfs http client for which there’s plenty of material.
Do you have access to a Mac or linux terminal? let’s try to generate the base64 string manually with the following command: echo -n "myProjectId:myKeySecret" | base64 -w 0 echo -n "27hXXX7LRsj:205XXX15b" | base64 -w 0
The resulting string would look like the below and let’s pass that one directly in the basic auth, without declaring the values string.
MjdoTTc1aDhRZXXXXXXXXXXXXXXXXXXXXXXXX2FhNzk2MDg1MzJmOTJkMTVi
you can use the Chrome developers console to get the base64 encoded string in windows.
navigate to the developers tools console and type btoa("myProjectId:myKeySecret"), the result will be the string you need:
The question right now is, how create my CID, cause this CID its yours, right?
From what I understand, I will have to create a folder, which will give me this CID, and with this cid I will upload my files that I need for the application
Hi Gabriel, happy that you managed to connect.
I am not fluent in java, but now that you have managed to open the connection using your Infura IPFS credentials, I think that you should be able to use the tutorial you were following to continue defining your IPFS java client and use its methods to upload files or folders to IPFS and get their CIDs. My guess is that the IPFS java client should have an add file method which you could use.
I can share some documentation which can maybe get you up to speed with IPFS.
Also the below is an example of how you would add files using the ipfs-http-client javascript library. As I was mentioning earlier, my guess is that the java client should have a similar method.