Open lidel opened 2 years ago
Heads up:
ipfs://
This code assumes every CID is CIDv0 (looks the same as Multihash, so it is parsed as Multihash here):
public InputStream getInputStream() throws IOException { Multihash filePointer = Multihash.fromBase58(location.toString().replaceFirst("ipfs://", "")); byte[] fileContents = new byte[0]; try { fileContents = ipfs.cat(filePointer); } catch (IOException e) { logger.error("Failed to retrieve object", e); return null; }
Try parsing ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi – it is not Base58 (it is CIDv1 in Base32), so will throw an exception.
ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
Always assume localtion is a CID and parse it using a library that understands CIDv1.
localtion
You can use CID implementation from java-cid, you can also peek at how CIDs are used in Peergos
See:
Happy to answer any questions / guide
cc @rlebre for awareness
Thank you very much for the heads up @lidel. I'll look into this soon and definitely reach you if a technical issue arises. Thanks!
Summary
Heads up:
ipfs://
addresses in this project will break when it attempts to read a CIDv1ipfs://
addressesProblem
This code assumes every CID is CIDv0 (looks the same as Multihash, so it is parsed as Multihash here):
Try parsing
ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
– it is not Base58 (it is CIDv1 in Base32), so will throw an exception.Solution
Always assume
localtion
is a CID and parse it using a library that understands CIDv1.You can use CID implementation from java-cid, you can also peek at how CIDs are used in Peergos
See:
Happy to answer any questions / guide
cc @rlebre for awareness