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:
parent
06fcc7f1ac
commit
3438860ae8
2 changed files with 62 additions and 0 deletions
|
@ -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],
|
||||
|
|
41
lib/fog/rackspace/requests/files/put_object.rb
Normal file
41
lib/fog/rackspace/requests/files/put_object.rb
Normal 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
|
Loading…
Add table
Reference in a new issue