Home
/ Topics / Predictions
Input files
Table of contents
Some models accept files as input, like images, audio, or video, zip files, PDFs, etc.
There are multiple ways to use files as input when running a model on Replicate. You can provide a file as input using a URL, a local file on your computer, or a base64-encoded object.
Option 1: Hosted file
Use a URL to provide a hosted file:
const fileInput = "https://example.com/path/to/your/file";
This is useful if you already have a file hosted somewhere on the internet.
Option 2: Local file
You can provide Replicate with a Blob
, File
, or Buffer
object, and the library will handle the upload for you. This will work for files up to 100MB:
import { readFile } from "node:fs/promises";
const fileInput = await readFile("./path/to/your/file");
Option 3: Data URI
Create a data URI consisting of the base64 encoded data for your file. This is only recommended if the file is less than 1MB:
import { readFile } from "node:fs/promises";
const data = (await readFile("./path/to/your/file")).toString("base64");
const fileInput = `data:application/octet-stream;base64,${data}`;
Using the file input
Once you have your file input ready, you can use it in your prediction:
const input = { file: fileInput };
const output = await replicate.run("your-model-id", { input });