Python Upload for Zip Artifacts
Last updated
cd /path/to/your/cube/project
zip -r cube-model.zip model/import json
import os
from pathlib import Path
import requests
# Configuration β replace with your values
endpoint_url = (
"https://api.app.euno.ai/accounts/YOUR_ACCOUNT_ID/"
"integrations/YOUR_INTEGRATION_ID/prepare-upload"
)
trigger_secret = "your_trigger_secret_here"
zip_file_path = "artifacts.zip"
headers = {
"authorization": f"Bearer {trigger_secret}",
"content-type": "application/json",
}
def get_signed_url():
"""Request a signed upload URL for the zip file."""
body = {"filename": Path(zip_file_path).name}
response = requests.post(endpoint_url, headers=headers, json=body, timeout=30)
if response.status_code != 200:
print(f"Failed to obtain signed URL (status {response.status_code}): {response.text}")
return None
payload = response.json()
upload_url = payload.get("upload", {}).get("url")
if not upload_url:
print("Signed upload URL not found in response:", json.dumps(payload)[:500])
return None
return upload_url, payload
def upload_file(upload_url):
"""Upload the zip file to the signed URL."""
try:
with open(zip_file_path, "rb") as file_handle:
response = requests.put(
upload_url,
data=file_handle,
headers={"content-type": "application/zip"},
timeout=120,
)
if response.status_code not in (200, 201):
print(f"Upload failed (status {response.status_code}): {response.text[:200]}")
return False
return True
except OSError as exc:
print("An error occurred during upload:", exc)
return False
def main():
print("Starting zip artifact upload...")
if not os.path.exists(zip_file_path):
print(f"Error: file '{zip_file_path}' not found.")
return False
print("Requesting signed URL...")
result = get_signed_url()
if not result:
return False
upload_url, meta = result
print("Signed URL obtained β uploading archive...")
if upload_file(upload_url):
print("Upload succeeded! Euno will start processing automatically.")
print(json.dumps(meta, indent=2))
return True
print("Upload failed.")
return False
if __name__ == "__main__":
main()curl -X POST \
-H "Authorization: Bearer YOUR_TRIGGER_SECRET" \
-H "Content-Type: application/json" \
-d '{"filename": "artifacts.zip"}' \
"https://api.app.euno.ai/accounts/YOUR_ACCOUNT_ID/integrations/YOUR_INTEGRATION_ID/prepare-upload"curl -X PUT \
-H "Content-Type: application/zip" \
--data-binary @artifacts.zip \
"SIGNED_URL_FROM_STEP_1"