[英]Rails 4 to pull files from folder and push to s3
I am using Rails 4. I need to create a project which can pull the files from a folder present in my system and push those files to s3 bucket one by one. 我正在使用Rails4。我需要创建一个项目,该项目可以从系统中存在的文件夹中提取文件,然后将这些文件逐个推送到s3存储桶。 After it is retrieved and pushed to s3, I want those files to be deleted from the folder.
检索并推送到s3后,我希望将这些文件从文件夹中删除。 I want this entire thing to be in a while() loop so that the loop is always checking for files in the folder.
我希望整个过程都在while()循环中,以便循环始终检查文件夹中的文件。
Please help me with this. 请帮我解决一下这个。
I'll recommend Fog for that purpose. 我会为此目的推荐雾 。 Its a great gem.
它是一个伟大的宝石。 Following is code using fog:
以下是使用fog的代码:
fog = Fog::Compute.new(
:provider => 'AWS',
:aws_access_key_id => 'YOUR KEY',
:aws_secret_access_key => 'YOUR SEC KEY'
)
directory = fog.directories.create(
:key => "BUCKET NAME",
:public => true
)
fog.put_object("BUCKET NAME", key, File.open('/your/file/location'))
File.delete('/your/file/location')
Put it in the loop as per your requirements 根据您的要求将其放入循环中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.