Skip to content

Handle files as input

UbiOps supports files as input to deployments or pipelines, but they do work a bit differently than other input data types. On this page you can find how to handle a file type input in your deployment code, and how to make requests with files.

Handling filess in deployment code

UbiOps passes the input data of a request to your request function in the data dictionary. If your input is a file the data dictionary will contain the absolute path to the file. Let's assume you have a deployment with input field csv which refers to a csv file input. In your deployment you can read in the csv input as follows:

import pandas as pd

class Deployment:

    def __init__(self, base_directory, context):
        print("Initialising My Deployment")

    def request(self, data):
        print("Processing request for My Deployment")

        # Here we retrieve the input file
        csv_path = data["csv"]
        csv = pd.read_csv(csv_path)

        # Here you can do something with the csv

        return {}

Making requests with files

When the data type of one of your deployment input fields is file, you will need to upload the file before creating the actual request. If you are using the WebApp you will simply be prompted to upload a file and the WebApp handles the rest, but if you're making the request programmatically you need to upload the file yourself. Below you can check examples of how to do that with the Python client librariy. We assume we are using the deployment example from the previous section.

# Specify a bucket to upload a file to, and the path to your file
bucket_name = 'bucket_name_example'
path_to_file = 'example.csv'

# Upload a file
file_uri = ubiops.utils.upload_file(api_client, project_name, path_to_file, bucket_name)

# Now we can make the request:
data = {'csv': file_uri}
response = api.deployment_requests_create(
    project_name=project_name, deployment_name=deployment_name, data=data
)

For more information on making requests with the Python client library, see how to make requests