首页 > 解决方案 > ostrio:files & Meteor 删除文件

问题描述

我目前正在使用 ostrio:files 来管理我的图片库。我没有找到有关如何删除/删除以编程方式插入和上传的图像的文档。这是关于大气的官方文档:https ://atmospherejs.com/ostrio/files

有人有想法吗?

标签: javascriptmeteor

解决方案


有关于如何从集合中删除文件的文档:

https://github.com/VeliovGroup/Meteor-Files/wiki/remove

在此页面上:https ://github.com/VeliovGroup/Meteor-Files/wiki/AWS-S3-Integration

有一些代码可以拦截文件删除:

  // Intercept FilesCollection's remove method to remove file from AWS:S3
  const _origRemove = UserFiles.remove;
  UserFiles.remove = function (search) {
    const cursor = this.collection.find(search);
    cursor.forEach((fileRef) => {
      _.each(fileRef.versions, (vRef) => {
        if (vRef && vRef.meta && vRef.meta.pipePath) {
          // Remove the object from AWS:S3 first, then we will call the original FilesCollection remove
          s3.deleteObject({
            Bucket: s3Conf.bucket,
            Key: vRef.meta.pipePath,
          }, (error) => {
            bound(() => {
              if (error) {
                console.error(error);
              }
            });
          });
        }
      });
    });

    //remove original file from database
    _origRemove.call(this, search);
  };
} else {
  throw new Meteor.Error(401, 'Missing Meteor file settings');
}

推荐阅读