UiPath Agents have been now been given the ability to be given a file directly, but a few steps are needed to use them fully and not all versions or Studio currently support them so they can be confusing to use.
Here is a rundown of how to use them and the important stuff to know.
Please note, the File Type input argument is in public preview at the time of writing this tutorial, so some of these aspects may have changed by the time you read it. I will try to update this when updates are provided.
Using Files in Agent Builder
Adding the new file type in agents is pretty easy, since you can simply reference them as a data type when adding an input argument alongside the other data types.
Simply doing this however is not enough for the agent to work with that file type and if you try to debug the agent you might get some output like this, stating the agent cannot read the file contents.
This is because, in order to read the file, the agent needs access to one of UiPaths built in Tools (these are new, and the one we need is the first one they made)
In Tools, search for an add the ‘Analyze Attachments’ tool, you dont have to do any configurations on the tool. It just works with the default settings.
Once you add this and run the agent it should now work!
Supported File Types
Do note, not every file type is supported. As of writing the following formats are supported
.gif, .jpe, .jpeg, .jpg, .pdf, .png, .webp
For more info on the built in tools see the UiPath documentation here.
Using the File type input when using an Agent in Studio
After publishing your agent you can work with it in studio (If you are working in a solution you can also reference the agent without publishing).
First things first, you need to make sure you have at least UiPath.System.Activities 25.10.0 to use the File Type input when running an agent. Older versions of the activity package will give an error popup when you try to refresh the inputs, stating
Object reference not set to an instance of an object.
You must also be on an up to date version of UiPath Studio, currently its only supported in the STS version, the LTS version should be able to run the agent, but you need the data mapping window (explained below), which isn’t implemented, so you have to pass a dictionary<string, object> containing the arguments and values.
If you are on a newer version of studio when you refresh you should be able to set the Input arguments to the ‘Data Mapping’ mode, then click on them to the the Data Mapping window, where you can easily populate the arguments on the agent.
In this example the agent only has one input, which is a File Type Input, but other input arguments will appear here too.
You can now pass any iResource to the agent by specifying it in this data mapping window (ideally you already have a variable that inherits iResource to be used).
The agent doesn’t need direct access to whatever file is specified by the iResource, meaning it can be a LocalResource, or a file from an email attachment, or on a sharepoint etc.
The file will then be downloaded locally in a temp path and then uploaded to orchestrator and transformed into what is called a “Job attachment”.