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

查看:155
本文介绍了如何在Rails上的ruby中使用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

谢谢!

Deb

推荐答案

使用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.jpg,则bucket仅是pics,而key1234/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

我从这里得到了答案:

I got the answer from here: How do I copy files between buckets using s3 from a rails application?

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

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