I am now using a hyperledger composer to make a food supply chain. I want to combine hyperledger composer and ipfs. How do I combine them?How should I combine hyperledger composer with IPFS?I wrote the application with hyperledger composer, but I don't know how to combine IPFS with hyperledger composer.I want to store images, files and other content on composer how to combine hyperledger composer and IPFS?
Asked
Active
Viewed 752 times
1 Answers
0
Yes, we can use Ipfs and Hyperledger composer together. First, you have to install ipfs in your system. you can follow this link. Then you need to connect ipfs in your application.
In your application, In js file where you need to store Image. There you have to just write ipfs connectivity code. When you run the application at that time just make sure ipfs daemon
started.
for example
function toIPFS(file) {
return new Promise(resolve => {
const reader = new FileReader();
reader.onloadend = function() {
const ipfs = window.IpfsApi('ipfs', 5001,{protocol : "https"}) // Connect to IPFS
const buf = buffer.Buffer(reader.result) // Convert data into buffer
ipfs.files.add(buf, (err, result) => { // Upload buffer to IPFS
if(err) {
return
}
let url = `https://ipfs.io/ipfs/${result[0].hash}`
resolve('resolved url');
})
}
reader.readAsArrayBuffer(file); // Read Provided File
});
}

Isha Padalia
- 877
- 7
- 24
-
,Thank you. But I am using hyperledger composer on ubuntu. I don't know how to implement IPFS and composer. – chenyu Dec 17 '18 at 06:03
-
do you have Ipfs in your System? – Isha Padalia Dec 17 '18 at 07:59
-
@ Isha Padalia,yes,I have,however, I don't know how to combine the hyperledger composer program I have written with IPFS to store images in the cto file. – chenyu Dec 17 '18 at 08:09
-
You can not store directly the images to Hyperledger Fabric, so first upload the image to IPFS, then you can store the returned URL of the image stored in ipfs. You can simply handle it with your front-end application. – Isha Padalia Dec 17 '18 at 08:18
-
,But I don't know the front end very much. Can you write a demo? For example, I am now uploading a picture in ipfs to get a hash, then how to store this hash on hyperledger composer? – chenyu Dec 17 '18 at 08:22
-
For Creating a Front-end application follow this link https://hyperledger.github.io/composer/v0.19/applications/web this. And for storage demo follow https://github.com/Preetam007/hyperledger_composer_file_storage this. And I already share a function on the post for connecting to the ipfs and it's return a URL. – Isha Padalia Dec 17 '18 at 08:45
-
github.com/Preetam007/hyperledger_composer_file_storage,@ Isha Padalia,How do I use this API in composer-cli? Create a new drug – chenyu Dec 17 '18 at 09:27