Method: Cnvrg::Datafiles#upload_cnvrg_image

Defined in:
lib/cnvrg/datafiles.rb

#upload_cnvrg_image(absolute_path, image_name, secret) ⇒ Object



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
# File 'lib/cnvrg/datafiles.rb', line 758

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