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)
|
merge_attributes(data.body)
|
||||||
else
|
else
|
||||||
data = connection.put_object(directory.key, key, body, options)
|
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
|
end
|
||||||
self.etag.gsub!('"','')
|
self.etag.gsub!('"','')
|
||||||
self.content_length = Fog::Storage.get_body_size(body)
|
self.content_length = Fog::Storage.get_body_size(body)
|
||||||
|
self.content_type ||= Fog::Storage.get_content_type(body)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,9 @@ module Fog
|
||||||
def put_object(bucket_name, object_name, data, options = {})
|
def put_object(bucket_name, object_name, data, options = {})
|
||||||
data = Fog::Storage.parse_data(data)
|
data = Fog::Storage.parse_data(data)
|
||||||
headers = data[:headers].merge!(options)
|
headers = data[:headers].merge!(options)
|
||||||
request({ :body => data[:body],
|
request({
|
||||||
:expects => 200,
|
:body => data[:body],
|
||||||
|
:expects => 200,
|
||||||
:headers => headers,
|
:headers => headers,
|
||||||
:host => "#{bucket_name}.#{@host}",
|
:host => "#{bucket_name}.#{@host}",
|
||||||
:idempotent => true,
|
:idempotent => true,
|
||||||
|
|
|
@ -118,8 +118,9 @@ module Fog
|
||||||
options.merge(metadata)
|
options.merge(metadata)
|
||||||
|
|
||||||
data = connection.put_object(directory.key, key, body, options)
|
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_length = Fog::Storage.get_body_size(body)
|
||||||
|
self.content_type ||= Fog::Storage.get_content_type(body)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,9 @@ module Fog
|
||||||
requires :body, :directory, :key
|
requires :body, :directory, :key
|
||||||
options['Content-Type'] = content_type if content_type
|
options['Content-Type'] = content_type if content_type
|
||||||
data = connection.put_object(directory.key, key, body, options)
|
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_length = Fog::Storage.get_body_size(body)
|
||||||
|
self.content_type ||= Fog::Storage.get_content_type(body)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -57,23 +57,24 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parse_data(data)
|
def self.get_content_type(data)
|
||||||
metadata = {
|
|
||||||
:body => nil,
|
|
||||||
:headers => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata[:body] = data
|
|
||||||
metadata[:headers]['Content-Length'] = get_body_size(data)
|
|
||||||
|
|
||||||
if data.respond_to?(:path) and !data.path.nil?
|
if data.respond_to?(:path) and !data.path.nil?
|
||||||
filename = ::File.basename(data.path)
|
filename = ::File.basename(data.path)
|
||||||
unless (mime_types = MIME::Types.of(filename)).empty?
|
unless (mime_types = MIME::Types.of(filename)).empty?
|
||||||
metadata[:headers]['Content-Type'] = mime_types.first.content_type
|
mime_types.first.content_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
end
|
||||||
metadata
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def self.providers
|
def self.providers
|
||||||
|
|
Loading…
Reference in a new issue