Reputation: 1876
I need to upload some zip files to a repository, we are using Raw since they are just files that later on we will download and we are only keeping them for versioning
so i have a local zip file and a repository in nexus, how can i upload it using API, do i need to create a folder in the repository first? or when i upload it the file i can specify the path and the API will create the folder structure in Nexus and put the zip file there?
i been trying to understand but shows mavens and other software's
https://help.sonatype.com/repomanager3/rest-and-integration-api/assets-api
thanks guys.
Upvotes: 1
Views: 5237
Reputation: 1876
I couldn't find a good way to see how to pass the arguments, so i did it using the api https://my_site.net/swagger-ui/#/components/uploadComponent and then i copied the curl to https://curl.trillworks.com/#python and removed thing that were not needed, i ended up with, hope works for some one on the future.
import requests
files = {
'raw.directory': (None, 'testing/testing2'), # folder structure you want in nexus
'raw.asset1': (open('path/to/your/file.zip', 'rb')),
'raw.asset1.filename': (None, 'desire_name.zip'), # this is the name you want to see in nexus
}
response = requests.post('https://my_site/service/rest/v1/components?repository={repo_name}'.format(repo_name="your_repo"), files=files, auth=(NEXUS_USER, NEXUS_PASSWORD), verify=False)
Upvotes: 3