2013-04-04 85 views
2

如何在不下載的情況下在霧中獲取s3對象的大小?霧 - 在S3中獲取對象的大小

例如:

connection.get_object(dir.key, latest_backup.key).body.size 

要求我先下載的對象。

如何在下載前瞭解尺寸?

+0

你嘗試訪問對象的元數據通過'metadata'方法? – pjam 2013-04-04 22:01:00

+0

我不知道有一個。我無法在文檔中看到它...可以提供示例或文檔鏈接嗎?乾杯。 – 2013-04-04 22:40:39

+0

對不起,我以爲我給你的鏈接,在這裏我找到了一個:http://docs.aws.amazon.com/AWSRubySDK/latest/frames.html,這個網站很爛,所以我不能給你確切的鏈接,但在s3中,有一個'S3Object'方法列表,它說明了一個元數據方法 – pjam 2013-04-04 22:46:14

回答

1

remote_file.content_length確實爲我的伎倆(霧1.21.0)

其中remote_file從遠程目錄中得到,像這樣:

def connection 
    Fog::Storage.new(fog_config) 
end 

def directory 
    connection.directories.get(bucket) 
end 

def remote_file 
    remote_files = directory.files.last 
end