2

This question already has an answer here:

I don't think it makes sense to store the "entire image" on the blockchain. I thought it would be better to store a reference to that image, but that means the actual image file will still be in a "centralized storage" such as s3.

What are the different ways of storing an image in the blockchain? And what is the currently "known ways" of efficientlu storing them?

I've seen project like Filecoin, Storj, Tiesdb, and many more, but still unsure on what would be an ideal solution. I want to build a blockchain based image album.

marked as duplicate by Richard Horrocks, Achala Dissanayake, Ismael, flygoing, Зелёный Feb 12 '18 at 3:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Possible answer to the question. – 1sn0s Feb 11 '18 at 16:47
  • @Grady If my ans is giving some direction, plz mark as accepted. – Jitendra Kumar. Balla Feb 11 '18 at 17:39
5

Yes, you're right. Saving entire image in eth is very costly. I'll suggest you to check off chain data storages like IPFS or Swarm (the ethereum community usually recommends it).

There are alternative APIs are available. Mentioned are two popular services and most of dev's are using. Both are distributed off chain storages.

I'll suggest you to check below link once.

Coming to your question. This is an example of how to store a reference to an image, stored in IPFS, in an ethereum smart contract.

contract ImageInfo{
   mapping(address=>Image[]) private images;
   struct Image{
      string imageHash;
      string ipfsInfo;
   }
   function uploadImage(string hash, string ipfs) public{
       images[msg.sender].push(Image(hash,ipfs)); //
   }
}

Above code is for just illustration. Modify the data structure as per your requirements. I have not added any security checks.

The idea is to first upload the image to ipfs/swarm/any other off chain data store, get the value calculate hash of image to contract. Download data(image) from offchain and calculate hash and check hash saved in contract.

I feel like the above solution is one of the best way to handle images, because all data is distributed using serverless architecture.

Not the answer you're looking for? Browse other questions tagged or ask your own question.