Files - Upload file
- TypeScript
- Python
Upload file to Gentrace with uploadFile()
. You can store files in Gentrace to use in your test cases.
Upload file to Gentrace with upload_file()
. You can store files in Gentrace to use in your test cases.
Example
uploadFile()
typescript
import {init ,uploadBuffer ,uploadFile } from "@gentrace/core";importfs from "fs/promises";import {File } from "@web-std/file";init ({apiKey :process .env .GENTRACE_API_KEY ?? "",});constbuffer = awaitfs .readFile ("./icon.png");consturlFile = awaituploadFile (newFile ([buffer ], "icon.png", {type : "image/png",lastModified :Date .now (),}),);console .log ("Gentrace URL (from File)",urlFile );
python
import osimport gentracefrom dotenv import load_dotenvload_dotenv()gentrace.init(api_key=os.getenv("GENTRACE_API_KEY"))with open("./icon.png", "rb") as f:url = gentrace.upload_file(f)print("Gentrace file URL: ", url)
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.
file: typing.Union[BinarySchema, bytes, io.FileIO, io.BufferedReader]
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.