【问题标题】:Set Content_Type with Fog on S3 without overwriting other metadata在 S3 上使用 Fog 设置 Content_Type 而不会覆盖其他元数据
【发布时间】:2014-02-14 20:02:23
【问题描述】:

我正在尝试使用副本重置存储桶中所有 mp3 的 content_type(如 Set content_type of Fog storage files on s3 中所述)。

但是,这会覆盖该项目的任何现有值,特别是 storage_class 和 owner 值。这些值对于存储桶中的所有文件都是相同的,因此我尝试将它们设置为选项。但是,当我在复制完成后查询文件的所有者时,我得到了 nil。

connection.directories.get('my_bucket').files.each do |f|
    content_type = case f.key.split(".").last
        when "mp3"
            "audio/mpeg"
        when "ogg"
            "audio/ogg"
        end

    options = {
        'Content-Type' => content_type,
        'Owner' => '{:display_name=>"myadmin", :id=>"myadminid"}',
        'Storage-Class' => 'STANDARD',
        'x-amz-metadata-directive' => 'REPLACE'
    }

    puts directory.files.get(f.key) if f.copy(f.directory.key, f.key, options)
end 

【问题讨论】:

    标签: ruby-on-rails amazon-web-services amazon-s3 fog


    【解决方案1】:

    我认为这可能只是选项的指定方式。我想也许您需要指定存储类,例如:

    x-amz-storage-class 而不是Storage-Class

    虽然我不确定所有者,但我认为这只是由于谁创建了对象(所以在复制的情况下,它可能会匹配运行复制操作的人)。我不确定这是否可以被覆盖。

    希望对您有所帮助。

    【讨论】:

    • 谢谢,这确实有帮助。我认为所有者也是自动生成的,所以我不确定为什么我在那里看到 nil,无论如何它似乎不会影响我的文件的功能。
    • 是的,nil 所有者也可能是一个错误。但是,如果它没有阻止您,这听起来像是目前不值得担心太多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 2022-01-26
    • 1970-01-01
    相关资源
    最近更新 更多