简体   繁体   English

如何使用雾来编辑s3上的文件?

[英]How can I use fog to edit a file on s3?

I have a bunch of files on s3. 我在s3上有一堆文件。 I have fog set up with a .fog config file so I can fire up fog and get a prompt. 我使用.fog配置文件设置了fog ,因此我可以启动fog并获得提示。 Now how do I access and edit a file on s3, if I know its path? 现在,如果我知道它的路径,我如何在s3上访问和编辑文件?

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. 最简单的方法是使用IRB或PRY获取文件的本地副本,或编写一个简单的脚本来下载,编辑然后重新上传。 Assume you have a file named data.txt. 假设您有一个名为data.txt的文件。

You can use the following script to initialize a connection to S3. 您可以使用以下脚本初始化与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

Edit the file using your favorite editor and then upload it to S3 again. 使用您喜欢的编辑器编辑文件,然后再次将其上传到S3。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM