downloadOpenAIFileContentTo

Downloads a file from the OpenAI Files API and writes its content to a KoryFile.

Return

The total number of bytes written.

Parameters

fileId

The ID of the file to download.

file

The destination file to write the content into.

onProgress

Optional listener for download progress (0.0–1.0).

Throws

if the destination file does not exist.

if the request fails.

if the OpenAI API returns an error.

Samples

// Load data into a file in a stream (uses a Sink from the file, does not throw an OutOfMemoryError).
client.downloadOpenAIFileContentTo(
    fileId = fileId,
    file = KoryFile.create("filename.ext"),
) { progress ->
    println("Downloading progress: ${progress.percentage}%")
}