539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
# File 'lib/cnvrg/datafiles.rb', line 539
def upload_tar_file(absolute_path, relative_path, commit_sha1)
begin
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"
begin
chunked_bytes = [100, (file_size*0.01)].min
total_yanked = ""
open(absolute_path, "rb") do |f|
total_yanked = f.read(chunked_bytes)
end
if !total_yanked.empty?
sha1 = OpenSSL::Digest::SHA1.hexdigest(total_yanked)
else
sha1 = OpenSSL::Digest::SHA1.file(absolute_path).hexdigest
end
rescue
sha1 = OpenSSL::Digest::SHA1.file(absolute_path).hexdigest
end
upload_resp = Cnvrg::API.request(@base_resource + "upload_tar_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
commit_sha1: commit_sha1, file_name: file_name,
file_size: file_size, file_content_type: content_type, sha1: sha1,
new_version:true})
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
return true
end
else
return false
end
rescue => e
return false
end
end
|