Guest User

Untitled

a guest
Dec 14th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. artifactory_url = 'artifactory.com' # your artifactory instance
  2. artifactory_username = 'username' # your username
  3. artifcatory_password = 'password' # your password
  4. content_type = 'application/java-archive' # your content-type header
  5. filename = 'file' # your file to upload (in current working directory)
  6.  
  7. url = artifactory_url + '/' + filename # where we want the file stored on artifactory
  8.  
  9. # checksums are useful for making sure the upload was successful
  10. headers = {'content-type': content_type,
  11. 'X-Checksum-Md5': hashlib.md5(open(filename).read()).hexdigest(),
  12. 'X-Checksum-Sha1': hashlib.sha1(open(filename).read()).hexdigest()}
  13.  
  14. with open(filename, 'rb') as f:
  15. r = requests.put(url,
  16. auth=(artifactory_username,
  17. artifactory_password),
  18. data=f,
  19. headers=headers)
  20.  
  21. # check for success
  22. if r.status_code != 201:
  23. print "Something went wrong"
  24. else:
  25. print r.json()['downloadUri'] # download url for this new artifact
Add Comment
Please, Sign In to add comment