Skip to content

Commit 1fdd3f8

Browse files
author
Glenn Snyder
committed
improving the scan upload method
1 parent f52598c commit 1fdd3f8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

blackduck/HubRestApi.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,11 +1262,17 @@ def remove_version_as_component(self, main_project_release, sub_project_release)
12621262

12631263
def upload_scan(self, filename):
12641264
url = self.get_apibase() + "/scan/data/?mode=replace"
1265-
files = {'file':open(filename,'rb')}
12661265
headers = self.get_headers()
1267-
headers['Content-Type'] = 'application/vnd.blackducksoftware.bdio+zip'
1268-
with open(filename,"rb") as f:
1269-
response = requests.post(url, headers=headers, data=f, verify=False)
1266+
if filename.endswith('.json') or filename.endswith('.jsonld'):
1267+
headers['Content-Type'] = 'application/ld+json'
1268+
with open(filename,"r") as f:
1269+
response = requests.post(url, headers=headers, data=f, verify=False)
1270+
elif filename.endswith('.bdio'):
1271+
headers['Content-Type'] = 'application/vnd.blackducksoftware.bdio+zip'
1272+
with open(filename,"rb") as f:
1273+
response = requests.post(url, headers=headers, data=f, verify=False)
1274+
else:
1275+
raise Exception("Unkown file type")
12701276
return response
12711277

12721278
def download_project_scans(self, project_name,version_name, output_folder=None):

0 commit comments

Comments
 (0)