Files

Create and use files within tasks
Files can be used to pass large amounts of data between tasks. Certain file types can be displayed directly in the UI, such as images, videos, audio, text, or CSVs (see File displays).

Creating files

Users can upload files directly to Airplane via task parameters or prompt inputs. When doing so, they will be greeted with a file input form:
Files can also be directly created within a task via the file uploads API. For example, you can download the source code for Airplane's website and upload it as a file:
typescript
Copied
1
const resp = await fetch("https://airplane.dev");
2
3
const myFile = airplane.file.upload(await resp.text(), "airplane.txt");
4
5
// you can display the file directly in the UI
6
await airplane.display.file(myFile);
7
8
// you can also pass the file to another task
9
await airplane.execute("my_task", { file: myFile });

Limitations

  • Maximum file size is 2Gb.
  • File URLs expire after 7 days. This may be relevant if you are using a file's URL directly, e.g. sending an email with the URL.

Examples

Passing a large SQL request into another task

typescript
Copied
1
const run = await airplane.sql.query("db", "select * from customers");
2
3
// Without creating the file, the SQL result might be too large to pass directly to another task.
4
const customerData = await airplane.file.upload(
5
JSON.stringify(run.output.Q1),
6
"customer_data.json",
7
);
8
9
// processData is a task that takes a file as input.
10
await processData({ data: customerData });

Upload a CSV file, change the column names to uppercase, and display the results

typescript
Copied
1
import airplane from "airplane";
2
// From https://www.npmjs.com/package/csv-parse
3
import { parse } from "csv-parse/sync";
4
5
export default airplane.task(
6
{
7
slug: "display_csv",
8
parameters: {
9
csv_upload: "upload",
10
},
11
},
12
async (params) => {
13
// Download from URL into memory.
14
const response = await fetch(params.csv_upload.url);
15
16
// Open the file as a CSV.
17
const parsedCSV = parse(await response.text());
18
19
// Convert the column names to uppercase.
20
const processedCSV = parsedCSV.map((row: string[], i: number) => {
21
if (i === 0) {
22
return row.map((col) => col.toUpperCase());
23
}
24
return row;
25
});
26
27
// Upload the new CSV.
28
const processedCSVFile = await airplane.file.upload(processedCSV.join("\n"), "processed.csv");
29
30
// Display the new CSV.
31
await airplane.display.file(processedCSVFile);
32
},
33
);

SDK reference

See File SDK reference for more information.