Class: Bkblz::Task::UploadFile

Inherits:
BaseTask
  • Object
show all
Defined in:
lib/bkblz/task/upload_file.rb

Constant Summary

Constants included from ClassMethods

ClassMethods::PARAM_SPEC

Instance Attribute Summary

Attributes inherited from BaseTask

#config, #result

Instance Method Summary collapse

Methods inherited from BaseTask

#initialize, #run

Methods included from ClassMethods

#check_one_of, #check_params, #check_required, #run, #task_param, #task_params

Methods included from TaskHelpers

#find_bucket_by_name

Constructor Details

This class inherits a constructor from Bkblz::Task::BaseTask

Instance Method Details

#run_internal(session, params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bkblz/task/upload_file.rb', line 21

def run_internal(session, params)
  file_name = if params[:file_name]
                params[:file_name]
              elsif params[:file_path]
                ::File.basename(params[:file_path])
              else
                raise 'missing either :file_name or :file_path param'
              end

  file_mtime = if params[:file_path]
                 ::File.mtime(params[:file_path])
               else
                 Time.now
               end.to_i * 1000

  bucket = find_bucket_by_name session, params[:bucket_name]
  size = file_size(params)

  file_data = {
    :file_name => file_name,
    :file_mtime => file_mtime,
    :file_size => size,
    :bucket => bucket,
  }

  if size > config.large_file_max_chunk_size
    upload_large_file session, params, **file_data
  else
    upload_file session, params, **file_data
  end
end