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 ariaholic
• 7,320 points
95 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,710 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
• 27,620 points
200 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 64 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
84 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
43 views
0 votes
1 answer
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
• 27,620 points
51 views
+1 vote
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.