将文件从url上传到s3存储桶 [英] upload file from url to s3 bucket

查看:153
本文介绍了将文件从url上传到s3存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku中运行一个nodejs程序,它为我提供了文件的URL.这些文件需要存储在s3存储桶中.

I have a nodejs program running in Heroku which gives me the URL of files. These files need to be stored in an s3 bucket.

据我了解,无法将文件从url直接上传到s3存储桶.

It is my understanding that there is no way to upload a file from a url directly to an s3 bucket.

您如何建议我从URL将文件获取到s3存储桶?我已经看到了有关使用EC2实例的讨论,但是如果可能的话,我想避免这种情况.无论如何,仅使用heroku和S3可以做到这一点?

How would you suggest I get the files from the URL to the s3 bucket? I've seen talk of using an EC2 instance but would like to avoid that if possible. Is there anyway to do this using just heroku and S3?

推荐答案

我知道它被标记为node-js,但是如果有人需要Ruby,请按以下步骤操作(Ruby AWS SDK v3):

I understand this is tagged node-js, but if someone needs this for Ruby here's how (Ruby AWS SDK v3):

obj = Aws::S3::Object.new(bucket_name: 'target-bucket', key: 'target-key')
obj.upload_stream do |write_stream|
  IO.copy_stream(URI.open('http://example.com/file.ext'), write_stream))
end

这篇关于将文件从url上传到s3存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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