Files API
Global files are the files that your organization stores outside any session. These endpoints upload, list, download and delete them. The endpoints for one session's files are on Sessions API. For the base URL and authentication, see API conventions. For the error codes, see Errors.
The first example is a complete program. The later examples use its client.
Endpoints
List global files
GET/v1/files
Lists your organization's global files.
This endpoint takes no parameters.
Response
| Field | Type | Description |
|---|---|---|
data | object[] | The files, each with path, size in bytes and lastModified. |
See Files.
curl https://api.steel.dev/v1/files \
-H "steel-api-key: $STEEL_API_KEY"import Steel from "steel-sdk";
const client = new Steel();
const files = await client.files.list();
for (const file of files.data) {
console.log(file.path, file.size);
}from steel import Steel
client = Steel()
files = client.files.list()
for file in files.data:
print(file.path, int(file.size))package main
import (
"context"
"fmt"
"log"
"github.com/steel-dev/sdk/go"
)
func main() {
if err := run(context.Background()); err != nil {
log.Fatal(err)
}
}
func run(ctx context.Context) error {
client := steel.NewClient()
files, err := client.Files.List(ctx)
if err != nil {
return err
}
for _, file := range files.Data {
fmt.Println(file.Path, file.Size)
}
return nil
}#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = steel_rs::Client::new();
let files = client.files().list().await?;
for file in files.data {
println!("{} {}", file.path, file.size);
}
Ok(())
}Upload a global file
POST/v1/files
Uploads a global file. The request is multipart/form-data.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
file | file or string · body | Yes | The file content, or a URL to download the file from. |
path | string · body | No | The path of the file in storage, such as datasets/. |
The response is 201:
Response
| Field | Type | Description |
|---|---|---|
path | string | The path of the file in storage. |
size | integer | The size in bytes. |
lastModified | string (date-time) | When the file was created. |
To copy a global file into a session, pass its path as file to Upload a file to a session. See Files.
curl -X POST https://api.steel.dev/v1/files \
-H "steel-api-key: $STEEL_API_KEY" \
-F "file=@dataset.csv" \
-F "path=dataset.csv"import { createReadStream } from "node:fs";
const file = await client.files.upload({
file: createReadStream("dataset.csv"),
path: "dataset.csv",
});
console.log(file.path);from pathlib import Path
file = client.files.upload(file=Path("dataset.csv"), path="dataset.csv")
print(file.path)import (
"io"
"os"
)
dataset, err := os.Open("dataset.csv")
if err != nil {
return err
}
defer dataset.Close()
file, err := client.Files.Upload(ctx, steel.FileUploadParams{
File: steel.F[io.Reader](dataset),
Path: steel.F("dataset.csv"),
})
if err != nil {
return err
}
fmt.Println(file.Path)let file = client
.files()
.upload(steel_rs::FileUploadParams {
path: Some("dataset.csv".to_owned()),
..steel_rs::FileUploadParams::new(steel_rs::Upload::open("dataset.csv").await?)
})
.await?;
println!("{}", file.path);Download a global file
GET/v1/files/{path}
Downloads one global file.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path | string · path | Yes | The path of the file. It can contain /. |
The response is the file, as application/octet-stream.
See Files.
curl https://api.steel.dev/v1/files/dataset.csv \
-H "steel-api-key: $STEEL_API_KEY" \
-o dataset.csvconst response = await client.files.download("dataset.csv");
const csv = await response.text();response = client.files.download("dataset.csv")
response.write_to_file("dataset.csv")import "io"
response, err := client.Files.Download(ctx, "dataset.csv")
if err != nil {
return err
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
return err
}
csv := string(body)let response = client.files().download("dataset.csv").await?;
let csv = String::from_utf8(response.to_vec())?;Delete a global file
DELETE/v1/files/{path}
Deletes one global file.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path | string · path | Yes | The path of the file. It can contain /. |
The response is 204 with no body.
See Files.
curl -X DELETE https://api.steel.dev/v1/files/dataset.csv \
-H "steel-api-key: $STEEL_API_KEY"await client.files.delete("dataset.csv");client.files.delete("dataset.csv")if err := client.Files.Delete(ctx, "dataset.csv"); err != nil {
return err
}client.files().delete("dataset.csv").await?;