UploadFile V2

upload_file_v2(public_api_client, file_path, artifact_type)
Expand source code
upload_file_v2(public_api_client, file_path, artifact_type):
"""
Description
-----------
High level wrapper function to upload artifact by presigned urls.
It checks to upload file in chunks or not based on the size.
If file_size ≤ chunk_size, will automatically use single upload, else use chunked upload.
Minimal size of chunk_size is 5 MB (5242880 bytes).
Args
----
public_api_client: QDC api client object.
file_path: Local path of the artifact to be uploaded.
artifact_type: Type of the artifact (TESTPACKAGE, TESTSCRIPT).
Returns
-------
uuid: uuid of the uploaded artifact.
None: In case of any failure.
Usages
------
# qdc_api is the name of the module
apk_file_to_upload = "C:\\Temp\\test.apk"
apk_uuid = qdc_api.upload_file_v2(public_api_client, apk_file_to_upload, ArtifactType.TESTPACKAGE)
"""
if not check_file_exists(file_path):
print(f"file path does not exist: {file_path}, exiting...")
return None
file_size = get_file_size(file_path)
file_name = get_filename(file_path)
public_api_client = get_client_with_headers_added(public_api_client)
print(f"start uploading file: {file_path}, type: {artifact_type}, size: {file_size} bytes")
# start_upload
start_upload_response = start_upload_v2(public_api_client, file_name, file_size, artifact_type)
print(f"success to start upload file: {file_path}, type: {artifact_type}, uuid: {start_upload_response.uuid}")
# continue_upload
parts = continue_upload_v2(file_path, start_upload_response.is_multipart_upload, start_upload_response.parts)
print(f"all chunks uploaded successfully for file: {file_path}")
# end_upload
end_upload_response = end_upload_v2(public_api_client, start_upload_response.uuid, start_upload_response.upload_id, parts)
print(f"upload completed: file: {file_path}, uuid: {end_upload_response.uuid}")
return end_upload_response.uuid

Description

High level wrapper function to upload artifact by presigned urls. It checks to upload file in chunks or not based on the size. If file_size ≤ chunk_size, will automatically use single upload, else use chunked upload. Minimal size of chunk_size is 5 MB (5242880 bytes).

Arguments

  • public_api_client: QDC api client object.
  • file_path: Local path of the artifact to be uploaded.
  • artifact_type: Type of the artifact (TESTPACKAGE, TESTSCRIPT).

Returns

  • uuid: uuid of the uploaded artifact.
  • None: In case of any failure.

Usages

  • qdc_api is the name of the module
apk_file_to_upload = "C:\\Temp\\test.apk"
apk_uuid = qdc_api.upload_file_v2(public_api_client, apk_file_to_upload, ArtifactType.TESTPACKAGE)