我正在尝试使用下面的代码更新保存在aws s3上的文件名
gem 'aws-sdk', '~> 2.3'
creds = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
s3 = Aws::S3::Resource.new(credentials: creds, region: ENV['AWS_REGION'])
bucket = s3.bucket(ENV['AWS_S3_BUCKET'])
filename = URI.unescape(document.url).split('/').last
new_file = 'new_file_name'
obj = bucket.object(filename) # create object of original file name
obj.move_to("#{bucket.name}/#{new_file}", acl: 'public-read')
obj = bucket.object(new_file)
更新时在行obj.move_to("#{bucket.name}/#{new_file}", acl: 'public-read')
上给出错误:
Aws::S3::Errors::NoSuchKey
The specified key does not exist.
有关如何在s3上重命名文件的任何建议或想法?
谢谢
您正在尝试将关键x
的对象移动到关键nil
。鉴于您的错误,我会首先尝试初始化一个新对象y
然后调用move_to。