Method: Cnvrg::Datafiles#upload_cnvrg_image

Defined in:
lib/cnvrg/datafiles.rb

#upload_cnvrg_image(absolute_path, image_name, secret) ⇒ Object



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/cnvrg/datafiles.rb', line 376

def upload_cnvrg_image(absolute_path, image_name,secret)
  file_name = File.basename relative_path
  file_size = File.size(absolute_path).to_f
  mime_type = MimeMagic.by_path(absolute_path)
  content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
  upload_resp = Cnvrg::API.request("images/#{image_name}/upload_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: absolute_path,
                                                                                 file_name: file_name,
                                                                                 file_size: file_size, file_content_type: content_type,
                                                                                 secret: secret})
  if Cnvrg::CLI.is_response_success(upload_resp, false)
    path = upload_resp["result"]["path"]
    s3_res = upload_large_files_s3(upload_resp, absolute_path)
    if s3_res
      Cnvrg::API.request(@base_resource + "update_s3", 'POST', {path: path, commit_id: upload_resp["result"]["commit_id"],
                                                                blob_id: upload_resp["result"]["id"]})
      return true
    end
  end
  return false

end