1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

first pass at push file

This commit is contained in:
Wesley Beary 2009-10-31 10:59:50 -07:00
parent 06fcc7f1ac
commit 3438860ae8
2 changed files with 62 additions and 0 deletions

View file

@ -28,6 +28,27 @@ module Fog
@connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}")
end
def parse_data(data)
metadata = {
:body => nil,
:headers => {}
}
if data.is_a?(String)
metadata[:body] = data
metadata[:headers]['Content-Length'] = metadata[:body].size.to_s
else
filename = File.basename(data.path)
unless (mime_types = MIME::Types.of(filename)).empty?
metadata[:headers]['Content-Type'] = mime_types.first.content_type
end
metadata[:body] = data.read
metadata[:headers]['Content-Length'] = File.size(data.path).to_s
end
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
metadata
end
def cdn_request(params)
response = @connection.request({
:body => params[:body],

View file

@ -0,0 +1,41 @@
unless Fog.mocking?
module Fog
module Rackspace
class Files
# Create a new object
#
# ==== Parameters
# * container<~String> - Name for container, should be < 256 bytes and must not contain '/'
#
def put_object(container, object, data)
data = parse_data(data)
response = storage_request(
:body => data[:body],
:expects => 201,
:headers => data[:headers,]
:method => 'PUT',
:path => "#{CGI.escape(container)}/#{CGI.escape(object)}"
)
response
end
end
end
end
else
module Fog
module Rackspace
class Servers
def put_container
end
end
end
end
end