如何在 ruby​​ on rails 中使用 aws-s3 或 aws-sdk gem 跨存储桶复制文件 [英] How to copy file across buckets using aws-s3 or aws-sdk gem in ruby on rails

查看:16
本文介绍了如何在 ruby​​ on rails 中使用 aws-s3 或 aws-sdk gem 跨存储桶复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

aws-s3 文档说:

The aws-s3 documentation says:

  # Copying an object
  S3Object.copy 'headshot.jpg', 'headshot2.jpg', 'photos'

但是,例如,我如何将 heashot.jpgphotos 存储桶复制到 archive 存储桶

But how do I copy heashot.jpg from the photos bucket to the archive bucket for example

谢谢!

黛布

推荐答案

使用 right_aws gem:

# With s3 being an S3 object acquired via S3Interface.new
# Copies key1 from bucket b1 to key1_copy in bucket b2:
s3.copy('b1', 'key1', 'b2', 'key1_copy')

我遇到的问题是,如果你有 pics/1234/yourfile.jpgbucket 只有 picskey1234/yourfile.jpg

the gotcha I ran into is that if you have pics/1234/yourfile.jpg the bucket is only pics and the key is 1234/yourfile.jpg

我从这里得到了答案:如何使用 Rails 应用程序中的 s3 在存储桶之间复制文件?

这篇关于如何在 ruby​​ on rails 中使用 aws-s3 或 aws-sdk gem 跨存储桶复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆