[英]How can I delete a file in AWS S3 with Sails? To upload, I use skipper-s3
I just made an upload file to AWS S3 with sails and skipper-3 and it work well. 我刚刚使用sails和skipper-3将文件上传到AWS S3,并且运行良好。 Now, how can I delete a file in AWS S3 with Sails?
现在,如何使用Sails删除AWS S3中的文件?
When I upload the file I store in the Database the URL to AWS S3. 当我上传文件时,我将URL存储到AWS S3。
You can use AWS-SDK directly or one of the many wrappers to it available at npm
. 您可以直接使用AWS-SDK或
npm
可用的众多包装之一。
Based on Amazon documentation you will have something like: 根据Amazon 文档,您将获得以下内容:
s3.deleteObject(params, function(err, data) {
if (err) console.log(err, err.stack); // error
else console.log(); // deleted
});
params
shall hold parameters as bucket, credentials, region, path. params
应保存以下参数:存储区,凭证,区域,路径。 See the example at Amazon nodejs examples . 请参阅Amazon nodejs示例中的示例 。
And, for sure you can use the AWS SDK for upload files and use other AWS services inside sails too. 而且,请确保您可以使用AWS开发工具包(SDK)上传文件,也可以在sails中使用其他AWS服务。
skipper-s3
already contains functions to read,list or remove files. skipper-s3
已经包含读取,列出或删除文件的功能。 I am using below code to remove some file from the AWS S3. 我正在使用以下代码从AWS S3中删除一些文件。 You can use it like this:
您可以像这样使用它:
var skipper = require('skipper-s3')({key: KEY,secret: SECRET,bucket: BUCKET}); skipper.rm(imageName,function(){});
Check the module functions on source code 检查源代码中的模块功能
For single image delete at a time First, install: 一次删除单个映像首先,安装:
npm install --save aws-sdk
Now write the below code: 现在编写以下代码:
var AWS = require("aws-sdk");
var s3 = new AWS.S3();
s3.config.update({
accessKeyId: "your aws key",
secretAccessKey: "your aws secret key"
});
s3.config.region = "your aws bucket region";
var params = {
Bucket: "Bucket name",
Key: "image name"
};
s3.deleteObject(params, function(err, data) {
if (err) console.log(err, err.stack);
// an error occurred
console.log(data, "tttttttttttt"); // successful response
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.