Local File Upload and Job Submission
FILE UPLAOD (Single Upload)
Step 1:
Call v1/customer/presign-url to obtain the presigned URL and file key path.
Example Request
curl --location 'https://optimus-api.crunchmediaworks.com/vod/v1/customer/presign-url' --header 'Content-Type: application/json' -H 'authorization: XXX' --data '{
"content_type": "video/quicktime",
"file_name": "Show.MOV"
}'
Example Response
{
"data": {
"fileKeyPath": "vod/input/bc96e670-4450-42c1-a53c-5175182040e2/7673b053-635f-4364-8296-64e25eeab4bb/Show.MOV",
"presigned_url": "https://cmw-optimus-media.s3.amazonaws.com/XXXX"
},
"message": "Pre-Signed generated successfully"
}
Step 2:
Open the local file in binary mode.
Send a PUT request to the presigned URL using the opened file as data.
Check the response status code to determine the success of the upload.
Step 3:
Use filekeypath generated in step 1 for Local Batch API to submit the job.
Example Request
curl -v 'https://optimus-api.crunchmediaworks.com/v1/local/batch' -H 'authorization: XXX' --data-raw '{"paths":["vod/input/bc96e670-4450-42c1-a53c-5175182040e2/7673b053-635f-4364-8296-64e25eeab4bb/Show.MOV"],"crunch_modes":["video_optimizer"]}'
Example Response
{
"data":null,
"message":"Batch request submitted successfully"
}
FILE UPLAOD (Multipart)
Step 1: Create Multipart Upload
Use the v1/customer/multipart/create API to initiate a multipart upload process.
Retrieve the key path and upload ID returned by the function.
Example Request
curl -v 'https://optimus-api.crunchmediaworks.com/vod/v1/customer/multipart/create' -H 'authorization: XXX' --data-raw '{"filename":"Show.MOV"}'
Example Response
{
"data": {
"upload_id": "XYZ",
"key_path": "vod/input/bc96e670-4450-42c1-a53c-5175182040e2/6d7cff03-d7b4-4a63-875f-30c6ca5738f3/Show.MOV"
},
"message": "Success"
}
Step 2: Generate Presigned URLs and Upload Parts:
Use the v1/customer/multipart/generate-url API to obtain a presigned URL for the current part.
Pass the key path, upload ID, part number, and authorization token as parameters.
Get the presigned URL from response
Example Request
curl -v 'https://optimus-api.crunchmediaworks.com/vod/v1/customer/multipart/generate-url' -H 'authorization: XXX' --data-raw '{ "key_path": "vod/input/bc96e670-4450-42c1-a53c-5175182040e2/6d7cff03-d7b4-4a63-875f-30c6ca5738f3/Show.MOV","part_number":1,"upload_id":"XYZ"}'
Example Response
{
"data": {
"url": "https://cmw-optimus-media.s3.amazonaws.com/XXXX”
},
"message": "Presign URL generated successfully"
}
Step 3: Send a PUT request to the presigned URL
Read the file in chunks of 5 MB (adjustable)
While there is data to read.
Send a PUT request to the presigned URL and provide the data chunk.
If the response status code is 200, retrieve the ETag from the response headers.
Add the part information (part number and ETag) to the parts list.
Increment the part number.
Chunk data should be 5MB or more depending on your network speed.
Step 4: Complete Multipart Upload:
Use the v1/customer/multipart/complete API to complete the multipart upload process.
Pass the key path, upload ID, parts list, and authorization token as parameters.
Example Request
curl -v 'https://optimus-api.crunchmediaworks.com/vod/v1/customer/multipart/complete' -H 'authorization: XXX' --data-raw '{ "key_path": "vod/input/bc96e670-4450-42c1-a53c-5175182040e2/6d7cff03-d7b4-4a63-875f-30c6ca5738f3/Show.MOV","parts":[{"etag":"cd1bc4546d6d0213cad4a57a0e6e9797","part_number":1},{"etag":"0f050df370da9dc2721917d4c4e22a5b","part_number":2},{"etag":"329f98d34f6d22d9a4a3f3021ec38f66","part_number":3},{"etag":"8a44e627bc86ce5f355e926a510efd6b","part_number":4}],"upload_id":"XYZ"}'
Example Response
{
"data": {
"Bucket": "cmw-optimus-media",
"BucketKeyEnabled": null,
"ChecksumCRC32": null,
"ChecksumCRC32C": null,
"ChecksumSHA1": null,
"ChecksumSHA256": null,
"ETag": ""f79f9046aff21671e422fd3a13dd0c66-14"",
"Expiration": null,
"Key": "vod/input/bc96e670-4450-42c1-a53c-5175182040e2/6d7cff03-d7b4-4a63-875f-30c6ca5738f3/Show.MOV",
"Location": "https://cmw-optimus-media.s3.amazonaws.com/vod%2Finput%2Fbc96e670-4450-42c1-a53c-5175182040e2%2Fab7b5129-09c0-496f-891b-be082efee32e%2FShow.MOV",
"RequestCharged": null,
"SSEKMSKeyId": null,
"ServerSideEncryption": "AES256",
"VersionId": null
},
"message": "Upload completed successfully"
}
Step 5: Submit batch job:
Use key path generated in step 1 for <Local Batch API> to submit the job.
curl -v 'https://optimus-api.crunchmediaworks.com/v1/local/batch' -H 'authorization: XXX' --data-raw '{"paths":["vod/input/bc96e670-4450-42c1-a53c-5175182040e2/f9dee65f-579e-4630-969e-35c86e0acdbe/Show.MOV"],"crunch_modes":["video_optimizer"]}'
Example Response
{
"data":null,
"message":"Batch request submitted successfully"
}
Multipart Upload Sample Python Code
Please update following details in python file.
file_name = 'Show.MOV'
local_file_path = '/Users/abhijit/Desktop/Automation/OPTIMUS_AUTOMATION/test/Show.MOV'
file_name = 'Show.MOV'
local_file_path = '/Users/abhijit/Desktop/Automation/OPTIMUS_AUTOMATION/test/Show.MOV'
Code Attached <python file>
Here we are using id_token (Bearer Token) as <auth_token>
$python3 testUpload.py <auth_token>
It will dump apis request/response , Once successfully uploaded. We can use the "key_path" and call https://docs.optimus.crunchmediaworks.com/localBatch
curl -v 'https://optimus-api.crunchmediaworks.com/v1/local/batch' -H 'authorization: XXX' --data-raw '{"paths":["vod1/input/bc96e670-4450-42c1-a53c-5175182040e2/6aae9b72-cb80-4ba0-8f98-ef6ba184c288/6min_1080pVideo.MOV"],"crunch_modes":["video_optimizer"]}'