Question

I'm trying to reset content_type for all the mp3s in a bucket using copy (as outlined in Set content_type of Fog storage files on s3).

However, this overwrites any existing values for the item, in particular, the storage_class and owner values. These values are the same for all the files in the bucket, so I tried setting them as options. However, when I query the owner of a file after the copy is complete, I get 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 
Was it helpful?

Solution

I think it may just be how the options are specified. I think perhaps you'll need to specify storage class, for instance, as:

x-amz-storage-class instead of Storage-Class

I'm not sure about owner though, I had thought that was just by virtue of who created the object (so in the case of the copy it will match who ran the copy operation presumably). I'm not sure that this can be overridden.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top