Skip to main content
Version: 4.7.28

Files - Upload buffer/bytes

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

Example

uploadBuffer()

typescript
import { init, uploadBuffer } from "@gentrace/core";
import fs from "fs/promises";
 
init({
apiKey: process.env.GENTRACE_API_KEY ?? "",
});
 
const buffer = await fs.readFile("./icon.png");
 
const urlBuffer = await uploadBuffer("icon.png", buffer);
console.log("Gentrace URL (from Buffer): ", urlBuffer);

Arguments

fileName: string

Since a buffer does not have a name, this provides a file name. This name is available in the Content-Disposition header.

buffer: Buffer

options?: FilePropertyBag

FilePropertyBag contains properties that augment the uploaded buffer with file metadata like MIME types.

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.