简体   繁体   中英

How to delete an image saved in IPFS blockchain?

I am working on a blockcahin based image sharing website in ethereum

function uploadImage(string memory _imgHASH,string memory _description ) public{
 //making sure image ipfs hash exist
 require(bytes(_imgHASH).length > 0);
  //making sure that the image description exist
  require(bytes(_description).length > 0);

  require(msg.sender != address(0));

  //increment image id
  imageCount ++;

  //add image to contract
  images[imageCount] = Image(imageCount,_imgHASH,_description,0,msg.sender);


  //trigger an image
  emit ImageCreated(imageCount, _imgHASH, _description, 0, msg.sender);
}

This is how you upload images but now I want user to delete images created by them how do i do it?

You cannot delete an image from IPFS the way you interact with the database. (giving the IPNS of the content and user sends an http request to delete it).

When you upload your content, you pin it to a node. Now the thing is the node that your content is pinned should be unpinned. So if you have a control over that node, If you started your own node, you unpin it and then ipfs will garbage collect it.

https://docs.ipfs.io/concepts/persistence/#garbage-collection

But if an image has been added and copied to another node, any person with the fingerprint can find it again. So whoever controls that node should unpin it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM