如何使用雾编辑在S3上的文件? [英] How can I use fog to edit a file on s3?

查看:169
本文介绍了如何使用雾编辑在S3上的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对S3一堆文件。我有雾设置了一个.fog配置文件,所以我可以启动,并得到一个提示。现在,我该如何访问和编辑在S3上的文件,如果我知道它的路径?

I have a bunch of files on s3. I have fog set up with a .fog config file so I can fire up fog and get a prompt. Now how do I access and edit a file on s3, if I know its path?

推荐答案

做最简单的事情可能是使用内部评级法或PRY获得文件的本地副本,或者写一个简单的脚本,下载,编辑,然后再-upload它。假设你有一个名为data.txt中的文件。

The easiest thing to do is probably to use IRB or PRY to get a local copy of the file, or write a simple script to download, edit and then re-upload it. Assume you have a file named data.txt.

您可以使用下面的脚本来初始化到S3的连接。

You can use the following script to initialize a connection to S3.

require 'fog'

connection = Fog::Storage.new({
  :provider                 => 'AWS',
  :aws_secret_access_key    => YOUR_SECRET_ACCESS_KEY,
  :aws_access_key_id        => YOUR_SECRET_ACCESS_KEY_ID
})

directory = connection.directories.get("all-my-data")

然后使用目录对象来获取你的文件的副本,你的本地文件系统上。

Then use the directory object to get a copy of your file on your local file-system.

local_file = File.open("/path/to/my/data.txt", "w")
file = directory.files.get('data.txt')
local_file.write(file.body)
local_file.close

用你喜欢的编辑器编辑文件,然后把它上传到S3了。

Edit the file using your favorite editor and then upload it to S3 again.

file = directory.files.get('data.txt')
file.body = File.open("/path/to/my/data.txt")
file.save

这篇关于如何使用雾编辑在S3上的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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