Class: FileFM::StreamingUploader
- Inherits:
-
Object
- Object
- FileFM::StreamingUploader
- Defined in:
- lib/filefm/streaming_uploader.rb
Defined Under Namespace
Classes: MultipartStream, StreamPart, StringPart
Class Method Summary collapse
Class Method Details
.put(to_url, params = {}, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/filefm/streaming_uploader.rb', line 79 def put(to_url, params = {}, &block) parts = [] content_file = nil params.each do |key, value| if value.kind_of?(File) filepath = value.path parts << StreamPart.new(value, File.size(filepath)) end end body_stream = MultipartStream.new(parts, block) url = URI.parse(to_url) headers = { 'Content-Length' => body_stream.size.to_s }.merge(params[:headers]) req = Net::HTTP::Put.new(url.path, headers) Log.debug "HEADERS: " + headers.inspect Log.debug "HOST: " + url.host Log.debug "PORT: " + url.port.to_s Log.debug "PATH: " + url.path req.content_length = body_stream.size #req.content_type = i req.body_stream = body_stream http = Net::HTTP.new(url.host, url.port) http.use_ssl = true if url.scheme == "https" res = http.request(req) res end |