Skip to main content
Version: 4.7.28

Files - Upload file

Upload file to Gentrace with uploadFile(). You can store files in Gentrace to use in your test cases.

Example

uploadFile()

typescript
import { init, uploadBuffer, uploadFile } from "@gentrace/core";
import fs from "fs/promises";
import { File } from "@web-std/file";
 
init({
apiKey: process.env.GENTRACE_API_KEY ?? "",
});
 
const buffer = await fs.readFile("./icon.png");
 
const urlFile = await uploadFile(
new File([buffer], "icon.png", {
type: "image/png",
lastModified: Date.now(),
}),
);
 
console.log("Gentrace URL (from File)", urlFile);

Arguments

file: File

Accepts a web standard File object. In Node.JS, you can install @web-std/file to create a File object from a Buffer or Uint8Array.

Use uploadBuffer() to avoid install extra dependencies.

Return value

url: string

The URL of the uploaded file with a gentrace.ai hostname. This image is only accessible with a valid API key.