class Bio::BaseSpace::UploadTask

Multipart file upload helper class.

TODO This file is not yet ported as the multipartFileUpload class is just mentioned in the comment section of the BaseSpaceAPI file.

Public Class Methods

new(api, bs_file_id, part, total, myfile, attempt) click to toggle source

Create a new upload task object.

api

BaseSpaceAPI instance.

bs_file_id

BaseSpace file ID.

part

Part number of the multi-part upload.

total

Total number of parts in the multi-part upload.

myfile

Local file to be uploaded.

attempt

Number of attempts that the file was previously uploaded (upload tries).

# File lib/basespace/model/multipart_upload.rb, line 34
def initialize(api, bs_file_id, part, total, myfile, attempt)
  @api         = api
  @part        = part       # part number
  @total       = total       # out of total part count
  @file        = myfile      # the local file to be uploaded
  @bs_file_id  = bs_file_id  # the baseSpace fileId
  @attempt     = attempt     # the # of attempts we've made to upload this guy
  @state       = 0           # 0=pending, 1=ran, 2=error
end

Public Instance Methods

call() click to toggle source

Upload a part of the file.

# File lib/basespace/model/multipart_upload.rb, line 50
def call
  # read the byte string in
  @attempt += 1
  trans_file = @file + @part.to_s
  cmd = "split -d -n #{@part}/#{@total} #{@file}"
  out = `#{cmd}`
  File.open(trans_file, "w") do |f|
    f.write(out)
  end
  # [TODO] confirm whether md5(out).digest is equivalent to MD5.digest (or MD5.hexdigest?)
  @md5 = Base64.encode64(Digest::MD5.digest(out))
  res = self.api.upload_multipart_unit(@bs_file_id, @part, @md5, trans_file)
  # puts "my result #{res}"
  File.delete(trans_file)
  if res['Response'].has_key?('ETag')
    @state = 1          # case things went well
  else
    @state = 2
  end
  return self
end
to_s() click to toggle source

Returns information about which part of which file is uploaded, including the total number of parts.

# File lib/basespace/model/multipart_upload.rb, line 73
def to_s
  return "#{@part} / #{@total} - #{@file}"
end
upload_file_name() click to toggle source

Returns the filename (without path) if the file to be uploaded.

# File lib/basespace/model/multipart_upload.rb, line 45
def upload_file_name
  return @file.split('/').last + '_' + @part.to_s
end