将文件从S3下载到Rails 4应用 [英] Download file from S3 to Rails 4 app
问题描述
我有一个运行日常任务并生成多个文件的AWS VM.我希望我的Rails应用程序下载这些文件并将它们放置在应用程序内的文件夹中. Ruby中有没有可以做到这一点的宝石或方法?
I have an AWS VM that runs a daily task and generates several files. I want my Rails app to download these files and place them in a folder within the app. Is there a gem or method in Ruby that can do this?
我知道如何使用s3cmd在bash中进行操作,我想我可以创建一个脚本来以这种方式获取它们,但是正在寻找一种更原生的Rails方式.
I know how to do it in bash with s3cmd and I guess I could create a script to get them this way, but looking for a more native rails way.
我正在使用这些文件中的数据作为应用程序,但我不希望用户能够下载它们.
I am using the data in these files for the app, but I don't want the users to be able to download them.
推荐答案
aws-sdk
v2 gem提供了一个简单的界面,用于从Amazon S3下载对象.
The aws-sdk
v2 gem provides a simple interface for downloading objects from Amazon S3.
require 'aws-sdk'
s3 = Aws::S3::Resource.new(
region: 'us-east-1',
access_key_id: '...',
secret_access_key: '...'
)
s3.bucket('bucket-name').object('key').get(response_target: '/path/to/file')
这篇关于将文件从S3下载到Rails 4应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!