How-to handle files (blobs) as input¶
UbiOps supports files (blobs) 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 blob type input in your deployment code, and how to make requests with blobs.
Handling blobs in deployment code¶
UbiOps passes the input data of a request to your request function in the data
dictionary. If your input is a blob the data dictionary will contain the path to the blob. 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 blob
csv_path = data["csv"]
csv = pd.read_csv(csv_path)
# Here you can do something with the csv
return {
}
Making requests with blobs¶
When the data type of one of your deployment input fields is a blob (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 and the R client libraries. We assume we are using the deployment example from the previous section.
# Define your input file by its path, for example, `"/home/user/image.jpg"`:
path_to_file = "path/to/my/file"
# Upload the file to UbiOps and save the `blob.id`, you will need this for making a request.
blob = api.blobs_create(project_name=project_name, file=path_to_file)
print(blob)
# Now we can make the request:
data = {'csv': blob.id}
response = api.deployment_requests_create(
project_name=project_name, deployment_name=deployment_name, data=data
)
# Define your input file by its path, for example, `"/home/user/image.jpg"`:
path_to_file = "path/to/my/file"
# Upload the file to UbiOps and save the `blob.id`, you will need this for making a request.
blob = blobs_create(file=path_to_file)
print(blob)
# Now we can make the request:
data = {'csv': blob.id}
response = deployment_requests_create(
deployment.name=deployment_name, data=data
)
For more information on making requests with the Python client library, see how to make requests