artifactory-client icon indicating copy to clipboard operation
artifactory-client copied to clipboard

Upload with checksum not working

Open AbezarBaker opened this issue 8 years ago • 5 comments

Hi I am trying to use the method "upload_with_checksum" but i get this error

C:\Ruby21-x64\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/ruby_workspace/samigit/PA/Utilities/bin/test_upload_artifactory.rb
C:/Ruby21-x64/lib/ruby/2.1.0/net/http/generic_request.rb:189:in `send_request_with_body_stream': Content-Length not given and Transfer-Encoding is not `chunked' (ArgumentError)
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http/generic_request.rb:132:in `exec'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1412:in `block in transport_request'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1411:in `catch'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1411:in `transport_request'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1384:in `request'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:218:in `block in request'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:853:in `start'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:217:in `request'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:109:in `put'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/resources/artifact.rb:447:in `upload'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/resources/artifact.rb:467:in `upload_with_checksum'
    from C:/ruby_workspace/samigit/PA/Utilities/bin/test_upload_artifactory.rb:23:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

Process finished with exit code 1

-------------The code is below------------

require 'artifactory'
require 'digest'
include Artifactory::Resource

ARTIFACTORY_ENDPOINT="http://<BAMS_DOMAIN>/artifactory"
LOCAL_REPOSITORY_KEY='xxx.xxx.local'

Artifactory.configure do |config|
  config.endpoint = ARTIFACTORY_ENDPOINT
  config.username = 'user'
  config.password = 'password'
end


@client = Artifactory::Client.new(endpoint: Artifactory.endpoint, username: Artifactory.username, password: Artifactory.password)
path_to_file='../Testdata/BAMS/TestFileForBams'
repository_path='Testing/AbezarTest/'
file_checksum = Digest::SHA1.file(path_to_file).hexdigest
file_name=File.basename(path_to_file)
artifact=Artifact.new(client: @client)
artifact.upload_with_checksum(LOCAL_REPOSITORY_KEY, path_to_file, repository_path+"#{file_name}",file_checksum)

Any idea what i am doing wrong here???

AbezarBaker avatar Apr 18 '16 17:04 AbezarBaker

You can actually provide the expected checksums as part of the normal upload requests, give this a go:

path_to_file = File.expand_path('../Testdata/BAMS/TestFileForBams')

artifact = Artifactory::Resource::Artifact.new(
  local_path: path_to_file,
  client: client,
  checksums: {
    'md5'  => Digest::MD5.file(path_to_file).hexdigest,
    'sha1' => Digest::SHA1.file(path_to_file).hexdigest,
  }
)

artifact.upload(
  LOCAL_REPOSITORY_KEY,
  repository_path+"#{file_name}",
)

schisamo avatar Apr 18 '16 19:04 schisamo

Hi thanks for the prompt reply. I will try that and let you know.One other question,i see there are newer versions of artifactory out there. But when i try to upgrade to 2.x.x and run the test above i now get another error saying 'Local destination folder is missing' . The issue i think is that the old version takes in a local destination parameter and when i upgrade to the new version im guessing that parameter isnt part of the upload signature?

AbezarBaker avatar Apr 18 '16 20:04 AbezarBaker

@AbezarBaker Not sure, we use a 3.9.x version of Artifactory here at Chef. The newest version is 4.7.3 is the newest version.

schisamo avatar Apr 18 '16 20:04 schisamo

Hi @schisamo is there a typo in your comment above?When i copied it to it says missing argument

artifact.upload( LOCAL_REPOSITORY_KEY, repository_path+"#{file_name}", )

AbezarBaker avatar Apr 18 '16 20:04 AbezarBaker

No luck @schisamo .Still get the same error

C:\Ruby21-x64\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/ruby_workspace/samigit/PA/Utilities/bin/test_upload_artifactory2.rb C:/Ruby21-x64/lib/ruby/2.1.0/net/http/generic_request.rb:189:in send_request_with_body_stream': Content-Length not given and Transfer-Encoding is notchunked' (ArgumentError) from C:/Ruby21-x64/lib/ruby/2.1.0/net/http/generic_request.rb:132:in exec' from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1412:inblock in transport_request' from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1411:in catch' from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1411:intransport_request' from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1384:in request' from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:218:inblock in request' from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:853:in start' from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:217:inrequest' from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:109:in put' from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/resources/artifact.rb:447:inupload' from C:/ruby_workspace/samigit/PA/Utilities/bin/test_upload_artifactory2.rb:32:in <top (required)>' from -e:1:inload' from -e:1:in `

'

Process finished with exit code 1

AbezarBaker avatar Apr 18 '16 20:04 AbezarBaker