如何使用S3图片网址删除S3对象?

时间:2019-03-11 06:44:09

标签: ruby-on-rails amazon-s3

我想通过查找以下网址从s3存储桶中删除图片。

https://s3-ap-southeast-1.amazonaws.com/s3dev-bucket/perspectives/images/3547/original/1.jpg?1471239691

3 个答案:

答案 0 :(得分:3)

使用#delete_object()

resp = client.delete_object({
  bucket: "s3dev-bucket", 
  key: "perspectives/images/3547/original/1.jpg", 
})

答案 1 :(得分:0)

您必须使用aws-sdk-s3 gem。 @John已经回答了它,对您有所帮助,这是示例S3创建对象红宝石代码。您必须更改函数调用才能删除对象。

require 'aws-sdk-s3'  # v2: require 'aws-sdk'

s3 = Aws::S3::Resource.new(region: 'us-west-2')

file = 'C:\file.txt'
bucket = 'my-bucket'

# Get just the file name
name = File.basename(file)

# Create the object to upload
obj = s3.bucket(bucket).object(name)

# Upload it      
obj.upload_file(file)

来源:https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-example-upload-bucket-item.html

答案 2 :(得分:0)

您可以尝试这样

 :: Spring Boot ::        (v2.1.3.RELEASE)

ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-03-11 15:16:13.709 ERROR 4652 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************
Description:    
Parameter 0 of method calculationRunner in com.example.demo.DemoApplication required a bean of type 'com.example.demo.Calculator' that could not be found.       
Action:
Consider defining a bean of type 'com.example.demo.Calculator' in your configuration.