Question:How I generate Cid before data stored?
See original GitHub issueI know the java-ipfs-api just invoke ipfs server. But now I want to get Cid of byte[] before invoke, I tried java-cid. But the Cid of java-ipfs-api is different from the Cid of java-cid(version 0).
this is my code.
String ss = "123321";
// 数据存储IPFS逻辑
try {
IPFS ipfs = new IPFS(Constants.IPFS_URL);// "/ip4/0.0.0.0/tcp/5001"
ipfs.refs.local();
NamedStreamable.ByteArrayWrapper file = new NamedStreamable.ByteArrayWrapper(ss.getBytes());
MerkleNode addResult = ipfs.add(file).get(0);
if (null != addResult && null != addResult.hash) {
System.out.println(addResult.hash.toString());
}
MessageDigest hasher = MessageDigest.getInstance("SHA-256");
byte[] hash = hasher.digest(ss.getBytes());
Multihash mhash = new Multihash(Multihash.Type.sha2_256, hash);
Cid cid = Cid.buildCidV0(mhash);
System.out.println(cid.toString());
} catch (IOException | IllegalArgumentException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
I get different result.
QmZE8aUxitmPdBjriC82rhhUmQbeh7KP4oEbgqBEATMct5
QmZKRiNkuVutGrvxWDr6dhp5zJa7sBM5HPWhuWF2mZgScm
Why? I doubt it maybe the ipfs server not only SHA256 byte[], but also other operation.
If anyone give advices. Thanks a lot!
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
Question:How I generate Cid before data stored? #64 - GitHub
I know the java-ipfs-api just invoke ipfs server. But now I want to get Cid of byte[] before invoke, I tried java-cid.
Read more >Generating a CID on the frontend, and then passing the files to ...
I am working on a small project that is really light on resources. It will allow users to upload a codebase to IPFS...
Read more >Create a node and return a Content Identifier (CID)
Store, fetch, and create verifiable links between peer-hosted datasets using the IPFS DAG API and CIDs. It's graphs with friends!
Read more >Node-less way to generate a CID that matches IPFS-Desktop ...
It looks like the problem is an IPFS node chunks data and the CID is for the DAG that links the files' chunks....
Read more >How to Obtain the CrowdStrike Customer Identification (CID)
To obtain the CID: In Google Chrome, go to https://falcon.crowdstrike.com/login/ . Populate the CrowdStrike account holder's credentials, and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In general you would need to implement the same chunking algorithm (rabin), encoding (protobufs) and data structures (unixfs) that ipfs uses internally.
i have created a module which can generate the correct file hash: https://github.com/rmnvalera/java-cid-generate-hash