mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[storage] properly update content-type at save time for file models
This commit is contained in:
parent
0960f8aa38
commit
f0f6924569
5 changed files with 22 additions and 18 deletions
|
@ -131,10 +131,11 @@ module Fog
|
|||
merge_attributes(data.body)
|
||||
else
|
||||
data = connection.put_object(directory.key, key, body, options)
|
||||
merge_attributes(data.headers)
|
||||
merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
|
||||
end
|
||||
self.etag.gsub!('"','')
|
||||
self.content_length = Fog::Storage.get_body_size(body)
|
||||
self.content_type ||= Fog::Storage.get_content_type(body)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ module Fog
|
|||
def put_object(bucket_name, object_name, data, options = {})
|
||||
data = Fog::Storage.parse_data(data)
|
||||
headers = data[:headers].merge!(options)
|
||||
request({ :body => data[:body],
|
||||
:expects => 200,
|
||||
|
||||
request({
|
||||
:body => data[:body],
|
||||
:expects => 200,
|
||||
:headers => headers,
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:idempotent => true,
|
||||
|
|
|
@ -118,8 +118,9 @@ module Fog
|
|||
options.merge(metadata)
|
||||
|
||||
data = connection.put_object(directory.key, key, body, options)
|
||||
merge_attributes(data.headers)
|
||||
merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
|
||||
self.content_length = Fog::Storage.get_body_size(body)
|
||||
self.content_type ||= Fog::Storage.get_content_type(body)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -64,8 +64,9 @@ module Fog
|
|||
requires :body, :directory, :key
|
||||
options['Content-Type'] = content_type if content_type
|
||||
data = connection.put_object(directory.key, key, body, options)
|
||||
merge_attributes(data.headers)
|
||||
merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
|
||||
self.content_length = Fog::Storage.get_body_size(body)
|
||||
self.content_type ||= Fog::Storage.get_content_type(body)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -57,23 +57,24 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
def self.parse_data(data)
|
||||
metadata = {
|
||||
:body => nil,
|
||||
:headers => {}
|
||||
}
|
||||
|
||||
metadata[:body] = data
|
||||
metadata[:headers]['Content-Length'] = get_body_size(data)
|
||||
|
||||
def self.get_content_type(data)
|
||||
if data.respond_to?(:path) and !data.path.nil?
|
||||
filename = ::File.basename(data.path)
|
||||
unless (mime_types = MIME::Types.of(filename)).empty?
|
||||
metadata[:headers]['Content-Type'] = mime_types.first.content_type
|
||||
mime_types.first.content_type
|
||||
end
|
||||
end
|
||||
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
||||
metadata
|
||||
end
|
||||
|
||||
def self.parse_data(data)
|
||||
{
|
||||
:body => data,
|
||||
:headers => {
|
||||
'Content-Length' => get_body_size(data),
|
||||
'Content-Type' => get_content_type(data)
|
||||
#'Content-MD5' => Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def self.providers
|
||||
|
|
Loading…
Reference in a new issue