【问题标题】:ostrio:files & Meteor Remove Fileostrio:files & Meteor 删除文件
【发布时间】:2018-05-21 20:28:39
【问题描述】:

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

有人有想法吗?

【问题讨论】:

  • 欢迎来到 Stack Overflow。我已经回答了你的问题,但你应该能够自己找到这些信息。提问前最好先做好自己的准备

标签: javascript meteor


【解决方案1】:

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

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');
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    相关资源
    最近更新 更多