0
我有一個執行分塊上傳的Dropbox CLI api,使用ruby-progressbar作爲上傳過程的指示器。紅寶石進度條上傳
它正常工作時,該文件是4MB(默認塊大小爲分塊上傳)之下,但它有問題,有什麼比是:
from /opt/rubies/2.0.0-p451/lib/ruby/gems/2.0.0/gems/ruby-progressbar-1.2.0/lib/ruby-progressbar/components/progressable.rb:45:in `progress='
from /opt/rubies/2.0.0-p451/lib/ruby/gems/2.0.0/gems/ruby-progressbar-1.2.0/lib/ruby-progressbar/base.rb:138:in `with_progressables'
from /opt/rubies/2.0.0-p451/lib/ruby/gems/2.0.0/gems/ruby-progressbar-1.2.0/lib/ruby-progressbar/base.rb:45:in `block in progress='
from /opt/rubies/2.0.0-p451/lib/ruby/gems/2.0.0/gems/ruby-progressbar-1.2.0/lib/ruby-progressbar/base.rb:148:in `with_update'
from /opt/rubies/2.0.0-p451/lib/ruby/gems/2.0.0/gems/ruby-progressbar-1.2.0/lib/ruby-progressbar/base.rb:45:in `progress='
from /Users/peterso/Projects/slipsquare/lib/slipsquare/middleware/chunked_upload.rb:20:in `block in call'
from /opt/rubies/2.0.0-p451/lib/ruby/gems/2.0.0/gems/dropbox-api-petems-1.1.0/lib/dropbox-api/client/files.rb:50:in `chunked_upload'
我認爲我在做一些愚蠢與總計算,即使上傳已經完全大小並完成,我仍然將其添加到進度條的總數中。
但我一直在看它一段時間,我似乎無法找到一種方式從欄獲取當前的進度,並將「如果progressbar.current_size + offset> total,完成進度條」。
的代碼看起來是這樣的:
file_name = env['chunked_upload_file_name']
contents = File.open(env['chunked_upload_file_name'])
total_size = File.size(env['chunked_upload_file_name'])
say "Total Size: #{total_size} bytes"
upload_progress_bar = ProgressBar.create(:title => "Upload progress",
:format => '%a <%B> %p%% %t',
:starting_at => 0,
:total => total_size)
response = env['dropbox-client'].chunked_upload file_name, contents do |offset, upload|
upload_progress_bar.progress += offset
end
哇,我不能相信我不只是想把偏移量看做是進步,現在感覺非常愚蠢。謝謝! :) – 2014-10-31 13:41:35