javascript - ostrio:files & Meteor 删除文件
问题描述
我目前正在使用 ostrio:files 来管理我的图片库。我没有找到有关如何删除/删除以编程方式插入和上传的图像的文档。这是关于大气的官方文档:https ://atmospherejs.com/ostrio/files
有人有想法吗?
解决方案
有关于如何从集合中删除文件的文档:
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');
}
推荐阅读
- vue.js - 如何在 vue 测试工具中禁用“检测到全局错误处理程序”警告
- python - 如何在python中应用幂函数
- python - 'pygame.event.get()' 的更快版本。为什么会错过事件以及为什么会延迟事件?
- pandas - 如何用wide_to_long或pivot重塑数据框?
- amazon-web-services - 我试图在 cloudformation 中获取文件以在 ec2 实例中生成,但似乎无法在 ec2 实例中看到它
- java - 在片段布局中创建动态视图的问题
- javascript - 如何在事件侦听器中为回调设置流类型
- elixir - 长生不老药中的多个条件修改变量
- mongodb - Mongodb 不承认该字段存在
- javascript - confirmjs 弹出背景关闭动画在 Firefox 中不起作用