简体   繁体   English

如何使用Sails删除AWS S3中的文件? 要上传,我使用skipper-s3

[英]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服务。

Your question is answered here too. 您的问题也在这里回答。

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.

相关问题 如何使用putObject从Node.js将CSV文件上传到AWS S3? - How can I use putObject to upload a csv file to AWS S3 from Nodejs? SailsJS skipper-s3文档建议S3存储桶应符合美国标准-但S3 UI中没有此类区域 - SailsJS skipper-s3 docs suggests S3 bucket should be in US standard - but no such region in S3 UI 如何在Sails JS和Skipper上设置S3缓存? - How Do You Set S3 Caching On Sails JS & Skipper? 如何使用Node.js将单个文件上传到AWS s3上的多个路径? - How can I upload single file to multiple path on aws s3 using nodejs? 如果我上传 1GB 文件然后删除它,AWS S3 会向我收费吗? - will i be charged by AWS S3 if i upload 1GB file and then delete it? 我想通过“适用于PHP的AWS开发工具包”将文件上传到AWS的S3 - I want to upload file to S3 of AWS by 'AWS SDK for PHP' 如何排除某些AWS S3存储桶文件 - How can I exclude some of AWS S3 bucket file 如何使用 docker 卷和 ubuntu 映像来访问从 AWS S3 下载的文件? - How can I use docker volume with ubuntu image to access a downloaded file from AWS S3? 如何将TeamCity的artifacts文件夹上传到AWS S3存储桶? - How can I upload TeamCity's artifacts folder into an AWS S3 bucket? 我如何使用AWS凭证读取没有S3 SDK的S3文件? - How can i read an s3 file without S3 SDK using aws credentials?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM