我尝试使用以下代码更新保存在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上重命名文件的任何建议或想法?
由于
答案 0 :(得分:0)
您正尝试将包含密钥x
的对象移至密钥nil
。鉴于您的错误,我会先尝试初始化一个新对象y
然后再调用move_to。