File Upload&Download with a Nexus Repository Rest Api

Çiğdem Kadakoğlu
3 min readMar 16, 2022

--

Nexus Repository-Rest Api-Bash

Hi everyone, I will show you how to upload raw file to Nexus Repository and download a package from Nexus Repository using rest api.

  • First of all, we will create BlobStores named devops and Repository named devopsrepo on Nexus.
cigdemkadakoglu

Click the “Save” button.

cigdemkadakoglu

Click the “Create repository” from “Repositories” .

cigdemkadakoglu

Click the “Save” button these configurations.

cigdemkadakoglu
  • Secondly, we have to encode username and password as base64 for basic authorization. Open bash terminal. You can open Git Bash terminal for Windows. My username and password are admin. Run the following command and copy the output.
echo -n 'admin:admin' | base64
  • Thirdly, let’s use Nexus Repository Rest Api.

Before using this command to upload file, i will change it.

curl -X 'POST' \
'http://<SERVER_IP_ADDRESS>:<PORT_NUMBER>/service/rest/v1/components?repository=<REPO_NAME>' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-H 'Authorization: Basic <NEXUSCRED>' \
-F 'raw.directory=<DIR_NAME>' \
-F 'raw.asset1=@<FILE_NAME>.zip;type=application/x-zip-compressed' \
-F 'raw.asset1.filename=<FILE_NAME>.zip'

REPO_NAME: devopsrepo

NEXUSCRED: YWRtaW46YWRtaW4=

DIR_NAME: devops

FILE_NAME: devops-1.0.0.0.zip

curl -X 'POST' \
'http://localhost:8082/service/rest/v1/components?repository=devopsrepo' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-F 'raw.directory=devops ' \
-F 'raw.asset1=@C:\Nexus\devops-1.0.0.0.zip;type=application/x-zip-compressed' \
-F 'raw.asset1.filename=devops-1.0.0.0.zip'
cigdemkadakoglu

Before using this command to download a file, i will change it.

curl -O --output-dir /some-dir http://<SERVER_IP_ADDRESS>:<PORT_NUMBER>/repository/<REPO_NAME>/<DIR_NAME>/<FILE_NAME>.zip

You can also copy link address and paste it.

cigdemkadakoglu

URL: http://localhost:8082/repository/devopsrepo/devops/devops-1.0.0.0.zip

curl -O --output-dir C:/Nexus/package http://localhost:8082/repository/devopsrepo/devops/devops-1.0.0.0.zip
cigdemkadakoglu

That’s it!

Hope you find my article helpful. I wish everyone an awesome day!

You can check this article: Nexus Repository Installation on Windows Server&Docker&Kubernetes

--

--

Çiğdem Kadakoğlu

Docker Captain🐳🇹🇷👩‍✈️ | Microsoft MVP | Instructor | Senior Cloud&DevOps Engineer | CK{A|AD}-AZ{104|204|305|400|800|801|900}-DP900-AI{900|102}-PL900🐧🐳🌼☕