Function upload_file

Source
pub async fn upload_file(
    client: &OpenAIClient,
    file_path: &Path,
    purpose: UploadFilePurpose,
) -> Result<FileObject, OpenAIError>
Expand description

Uploads a file to OpenAI.

This requires multipart form data:

  • A “file” field with the actual file bytes
  • A “purpose” field with the reason for upload (e.g. “fine-tune”)

The purpose is required by the API.

§Parameters

  • client - The OpenAI client.
  • file_path - Path to the local file to upload.
  • purpose - The file’s intended usage (e.g. UploadFilePurpose::FineTune).

§Returns

A FileObject containing metadata about the newly uploaded file.

§Errors

Returns OpenAIError if the network request fails, the file can’t be read, or the API returns an error.