Ⅰ. Get file list by warehouse name
import requests
import json
# 文件列表 参数 仓库名称 返回code 200
# 请求方式: GET
url = '192.168.1.111:8081'
auth = ("admin", "admin123")
res = requests.get(
url='http://{0}/service/rest/v1/components'.format(url),
params={"repository": "test"},
auth=auth
)
x = json.loads(res.content)
Ⅱ. Upload files to the warehouse
import requests
import json
# 文件上传到仓库 参数 仓库名称 、文件流、文件名、路径 返回code 204
# 请求方式 POST formData
url = '192.168.1.111:8081'
auth = ("admin", "admin123")
path = "D:\\test.txt"
file = open(path, 'rb')
res = requests.post(
url='http://{0}/service/rest/v1/components'.format(url),
params={"repository": "test"},
files={"raw.asset1": file},
data={
"raw.asset1.filename": 'test.txt',
"raw.directory": "/tmp"
},
auth=auth
)
print(res.status_code)
Ⅲ. Create warehouse
import requests
import json
url = '192.168.1.111:8081'
auth = ("admin", "admin123")
data = {
"name": "tttt", # 仓库名称
"online": True,
"storage": {
"blobStoreName": "default",
"strictContentTypeValidation": True,
"writePolicy": "allow"
},
"cleanup": {
"policyNames": [
"string"
]
}
}
res = requests.post(
url='http://{0}/service/rest/beta/repositories/raw/hosted'.format(url),
json=data,
auth=auth
)
# 注意:此接口支持的nexus版本为3.24