Method: Cnvrg::Files#upload_image

Defined in:
lib/cnvrg/files.rb

#upload_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message, commit_id) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/cnvrg/files.rb', line 237

def upload_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message, commit_id)
  file_name = File.basename absolute_path
  file_size = File.size(absolute_path).to_f
  if is_base

    content_type = "application/zip"
  else
    content_type = "application/gzip"
  end
  begin
    upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
                                                                                              file_name: file_name,
                                                                                              image_name: image_name,
                                                                                              file_size: file_size,
                                                                                              file_content_type: content_type,
                                                                                              is_public: is_public,
                                                                                              project_slug: @project_slug,
                                                                                              commit_id: commit_id,
                                                                                              dpkg: dpkg,
                                                                                              py2: libraries,
                                                                                              py3: libraries,

                                                                                              bash_history: bash,
                                                                                              commit_message: message,
                                                                                              is_base: is_base})
    # puts upload_resp
    if Cnvrg::CLI.is_response_success(upload_resp, false)
      s3_res = upload_large_files_s3(upload_resp, absolute_path)
      if s3_res
        commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
        if Cnvrg::CLI.is_response_success(commit_resp, false)
          return commit_resp["result"]["image"]
        else
          return false
        end

      end
    end
    return false
  rescue => e
  end

end