Files - Upload buffer/bytes
- TypeScript
- Python
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";importfs from "fs/promises";init ({apiKey :process .env .GENTRACE_API_KEY ?? "",});constbuffer = awaitfs .readFile ("./icon.png");consturlBuffer = awaituploadBuffer ("icon.png",buffer );console .log ("Gentrace URL (from Buffer): ",urlBuffer );
python
import gentracegentrace.init(api_key=os.getenv("GENTRACE_API_KEY"))with open("./icon.png", "rb") as f:# Remember to specify the file extension! The Gentrace UI relies on the file# extension to render file contents correctly.url = gentrace.upload_bytes("gentrace-icon.png", f.read())print("Uploaded URL: ", url)
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.
file_name: str
Since a buffer does not have a name, this provides a file name. This name is available in the Content-Disposition header.
buffer: bytes
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.