upload file from url to s3 bucket

走远了吗. 提交于 2020-05-14 10:43:48

问题


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.

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

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?


回答1:


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


来源:https://stackoverflow.com/questions/45947814/upload-file-from-url-to-s3-bucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!