使用Ruby写入AWS S3预签名URL [英] Write to a AWS S3 pre-signed url using Ruby

查看:90
本文介绍了使用Ruby写入AWS S3预签名URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用预签名的URL将文件上传到S3

I want to upload a file to S3 using a pre-signed url

首先,我使用url_for(:write)创建一个签名的URL

First I create a signed url using url_for(:write)

s3object = S3.buckets['myBucket'].objects['someFolder/testFile.txt']
url = s3object.url_for(:write) #

然后我得到了预期的网址.

And I get the url as expected.

https://s3.amazonaws.com/myBucket/someFolder/testFile.txt?AWSAccessKeyId=AKJFGKJASGK......

但是现在我想使用此URL上传一些内容 我假设有一种方法可以从该URL获取s3对象,在该对象上可以使用'write'方法.

But now I want to upload something using this url I's assume that there is a way to get an s3 object from that url on which I can use the 'write' method.

类似于obj = getObjectFromUrl(url)

有这种方法吗?

如果没有,我该如何使用该URL将内容上传到s3?

If not, how should I use this url to upload something to s3?

我可能应该解释一下. 我创建URL是为了进行测试. 当我将要处理它时,我将只有URL. 仅使用URL,就必须上传文件.

I probably should explain. I create the URL for testing sake. When I will be working on it, I will only have the URL. Using the URL alone, I will have to upload a file.

推荐答案

通过当前适用于Ruby的AWS开发工具包文档,建议的方法是仅对s3对象调用read.如果您已经拥有s3对象,则应该能够直接从该对象本身进行读取.另外,如果您希望流式传输读取的文件,则有一种流式传输下载的方法. AWS S3对象文档

Via the current AWS SDK documentation for Ruby, the suggested method is to simply call read on your s3 object. If you already have the s3 object, you should be able to read directly from the object itself. Also, there is a method for streaming downloads if you wish to stream a file read. AWS S3 Object Documentation

obj.write('abc')
puts obj.read
#=> abc

这篇关于使用Ruby写入AWS S3预签名URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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