How to upload and download artifacts using Artifactory REST API? [Video]

How to upload and download artifacts using Artifactory REST API? [Video]

AuthorFullName__c
Joey Naor, Patrick Russell
articleNumber
000004933
ft:sourceType
Salesforce
FirstPublishedDate
2020-11-18T11:55:17Z
lastModifiedDate
2025-02-11
VersionNumber
14

How to upload/deploy and download artifacts using Artifactory REST API?


Video Transcript:
Hello everyone and welcome to another video. My name is Patrick, and I'm with the JFrog support team. 
Today, we'll be going over how to upload and download artifacts to JFrog Artifactory using the REST API.


Let's first cover how to upload a file in Artifactory. In Linux, you use the libcurl CLI, also known as just curl, to interact with platforms using the REST API.

First, you need to type in the command curl. Then, you need to specify your credentials. You can use -u to supply basic username-password credentials, or you can supply the authorization Bearer header along with an Artifactory identity token.
The -X PUT command specifies the REST API method used in this context. A PUT command will upload a file. The -T flag specifies where on the local file system curl can locate the file.

Finally, you type in the URL of the Artifactory application. The /artifactory that comes after the port (e.g., 8082) is the context. You have to specify the context to direct the JFrog router on which microservice is supposed to receive the request. In this case, we're uploading a file to Artifactory, so artifactory is the context.

Over on my JFrog VM, I have a file. I type in -u followed by my username, then -X PUT, and -T to specify the file I want to upload. Finally, I type out the Artifactory URL, which in this case is on my localhost.

This is an example of deploying the file into a folder in the repository. Since I have not specified a password in the command itself, I can type in my password here, and no one will be able to see it.

Success! I have now uploaded a file to Artifactory within that directory.

Let's head back to the slide deck.

To download a file, a very similar command can be used. The key difference here is that instead of using a PUT request, we use a GET request. Unsurprisingly, this will download the file.

The -o parameter will save the file to a specific location. The same URL we used to upload the file can be used to download it—the only change is the method.

One important thing to remember is that when downloading binary files, it's important to use -o or another command to save the output to a file. Curl will warn you, but it is still possible to mess up your terminal session due to special characters being printed to standard output.

Let's go ahead and download our example file.

I'm going to copy and paste the URL here. Notice that I am not specifying -X GET—this is because GET is the assumed default action of curl.

It looks like I have received the same file I just uploaded—very nice!

One last REST API command I want to demonstrate is a more complex one. You can download all of the contents of a repository by prepending a specific command path.

You're already familiar with the rest of the curl command, but take a look at this addition: if you add /api/archive/download, you can request Artifactory to zip up the contents of the repository and return it as a zip archive.

Make sure to add the archiveType parameter at the end to specify the desired archive format. Check out the JFrog Help Center for a full guide on all the different URL paths Artifactory supports.

Make sure that when using special characters like ?, you enclose the URL in double quotes.

This concludes this video on how to upload and download artifacts to JFrog Artifactory. Thank you so much for watching! Feel free to leave a comment below or get in touch through the feedback button in the JFrog Help Center.

Have a great day—bye!