Inference Logoinference.sh

Files

Upload and download files programmatically.


Automatic Upload

Local file paths and data URIs are uploaded automatically:

1result = client.run({2    "app": "image-processor",3    "input": {4        "image": "/path/to/image.png"  # Uploaded automatically5    }6})

Manual Upload

1from inferencesh import UploadFileOptions2 3# Upload from path4file_obj = client.upload_file("/path/to/image.png")5print(f"URI: {file_obj['uri']}")6 7# Upload from bytes8file_obj = client.upload_file(9    b"raw bytes data",10    UploadFileOptions(11        filename="data.bin",12        content_type="application/octet-stream"13    )14)15 16# Upload with options17file_obj = client.upload_file(18    "/path/to/image.png",19    UploadFileOptions(20        filename="custom_name.png",21        content_type="image/png",22        public=True  # Make publicly accessible23    )24)

Upload Options

1from inferencesh import UploadFileOptions2 3UploadFileOptions(4    filename="custom.png",     # File name5    content_type="image/png",  # MIME type6    path="/custom/path",       # Custom storage path7    public=True                # Make publicly accessible8)

Use Uploaded Files

1file = client.upload_file("/path/to/image.png")2 3result = client.run({4    "app": "image-processor",5    "input": {"image": file["uri"]}6})

Download Results

1import requests2 3result = client.run(params)4output_url = result["output"]["image"]["uri"]5 6# Download7response = requests.get(output_url)8with open("output.png", "wb") as f:9    f.write(response.content)

File Class (App Development)

When building apps in Python, use the File class:

python
1from inferencesh import File2 3# From path4file = File(path="/path/to/file.png")5 6# With metadata7file = File(8    path="/path/to/file.png",9    content_type="image/png",10    filename="custom.png"11)12 13# Check existence14if file.exists():15    print(f"Size: {file.size} bytes")

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.