Class: Slipsquare::Middleware::ChunkedUpload

Inherits:
Base
  • Object
show all
Defined in:
lib/slipsquare/middleware/chunked_upload.rb

Constant Summary

Constants inherited from Base

Base::CLEAR, Base::GREEN, Base::RED, Base::YELLOW

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Slipsquare::Middleware::Base

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/slipsquare/middleware/chunked_upload.rb', line 6

def call(env)
  say "Starting chunked upload"
  
  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        

  say "File uploaded successfully!"
  
  @app.call(env)
end