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

发布于 2024-12-17 08:09:15 字数 98 浏览 7 评论 0原文

我在 s3 上有一堆文件。我使用 .fog 配置文件设置了雾,这样我就可以启动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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灰色世界里的红玫瑰 2024-12-24 08:09:16

最简单的方法可能是使用 IRB 或 PRY 获取文件的本地副本,或者编写一个简单的脚本来下载、编辑然后重新上传它。假设您有一个名为 data.txt 的文件。

您可以使用以下脚本初始化与 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")

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

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。

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

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.

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文