我正在以太坊中开发基于区 block 链的图像共享网站
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);
}
这是您上传图片的方式,但现在我希望用户删除他们创建的图片,我该怎么做?
最佳答案
您不能以与数据库交互的方式从 IPFS 中删除图像。 (提供内容的 IPNS,用户发送 http 请求删除它)。
当您上传您的内容时,您将其固定到一个节点。现在问题是您的内容被固定的节点应该被取消固定。因此,如果您可以控制该节点,如果您启动了自己的节点,您可以取消固定它,然后 ipfs 将对其进行垃圾回收。
https://docs.ipfs.io/concepts/persistence/#garbage-collection
但是如果一个图像已经被添加并复制到另一个节点,任何有指纹的人都可以再次找到它。因此,无论谁控制该节点,都应该取消固定它。
关于blockchain - 如何删除保存在 IPFS 区 block 链中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70650915/