How to store picture s in a hyperledger blockchain channel

0 votes
In my Hyperledger fabric project, I have a scenario where one of the asset is of type (images). How do I handle this asset in chaincode and are there any samples i can refer to (preferebly node.js).
Jun 16, 2018 in Blockchain by aryya
• 7,460 points
1,366 views

1 answer to this question.

0 votes

You can hold images as encrypted characters such like base64 in Fabric Network.
That was once mentioned in IBM DeveloperWorks Blog, but I can't find the article.

If you use Hyperledger Composer, I think assigning an image to a property of the asset is useful.

In my case, tx is submitted from node.js server like below.

'use strict'

const util = require('util');
var fs = require('fs');
const readFile = util.promisify(fs.readFile);

const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
this.bizNetworkConnection = new BusinessNetworkConnection();
this.cardName = '<REPLACE_CARD_NAME>';

async function createAsset(imgPath) {
    try {
        // Connect to Fabric Network.
        let definition = await this.bizNetworkConnection.connect(this.cardName)
        let factory = definition.getFactory();

        // Create a new asset which have property for base64 image.
        let newAsset = factory.newResource('com.namespace.your', 'AssetName', 'assetId');
        newAsset.imageBase64 = await readFile(imgPath,'base64');

        // Add the Asset to AssetRegistry.
        let assetRegistry = await this.bizNetworkConnection.getAssetRegistry('com.namespace.your.AssetName');
        await assetRegistry.add(newAsset);
    } catch (err) {
        console.error(err);
    } finally {
        this.bizNetworkConnection.disconnect();
    }
}
answered Jun 16, 2018 by charlie_brown
• 7,720 points

Related Questions In Blockchain

0 votes
1 answer

How to join a peer to a channel in Hyperledger Fabric?

When you run the command: peer channel create ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 26,740 points
2,108 views
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,594 views
+1 vote
1 answer

How does a blockchain work in hyperledger framework?

Hyperledger Composer simplifies application development on top ...READ MORE

answered Apr 19, 2018 in Blockchain by Christine
• 15,790 points
1,103 views
0 votes
1 answer

In a Blockchain, how difficult is it to modify the third to last block?

Technically, it's not difficult at all, all ...READ MORE

answered Apr 20, 2018 in Blockchain by Christine
• 15,790 points
1,044 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,472 views
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,740 points
1,039 views
+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP