11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/cifrado/streaming_uploader.rb', line 11
def put(to_url, params = {})
file = params[:file]
= params[:headers] || {}
chunker = nil
rate_limit = nil
rate_limit = Cifrado::RateLimit.new(params[:bwlimit]) if params[:bwlimit]
if file
.merge!({ 'Content-Length' => File.size(file.path).to_s })
chunker = lambda do
chunk = file.read(4096).to_s
rate_limit.limit(chunk.size) if rate_limit
if block_given? and chunk.size > 0
yield chunk.size
end
chunk
end
end
Excon.put to_url,
:headers => ,
:request_block => chunker
end
|