![](/img/trans.png)
[英]How do I open a CSV file that I uploaded with Carrierwave and Fog to Amazon S3?
[英]How can I use fog to edit a file on s3?
我在s3上有一堆文件。 我使用.fog配置文件設置了fog
,因此我可以啟動fog
並獲得提示。 現在,如果我知道它的路徑,我如何在s3上訪問和編輯文件?
最簡單的方法是使用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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.