![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Upload an Image File to an AI Provider (OpenAI, Google, Antropic, X)See more AI ExamplesUploads an image file to an AI provider using the provider's File API and returns theid that can later be used to reference the file in an query. This currently works with ChatGPT and Gemini, but not other AI's. Most AI's currently don't have the ability to reference pre-uploaded image data in conversations.Note: This example requires Chilkat v11.4.0 or greater.
load ./chilkat.dll set success 0 set ai [new_CkAi] # Can currently be "openai" or "google" because these are the only AI's that can reference pre-loaded image data by file ID. CkAi_put_Provider $ai "openai" # Use your provider's API key. CkAi_put_ApiKey $ai "MY_API_KEY" # We can upload directly from a file in the filesystem, or from a Chilkat BinData. set contentType "image/jpeg" set localFilePath "qa_data/jpg/starfish.jpg" set filenameOnServer "starfish.jpg" # Upload directly from a file. set file_id [CkAi_uploadFile $ai $localFilePath $contentType] if {[CkAi_get_LastMethodSuccess $ai] == 0} then { puts [CkAi_lastErrorText $ai] puts "AI File Upload Failed." } else { puts "File ID: $file_id" puts "File uploaded." } # Upload from the contents of a Chilkat BinData set bd [new_CkBinData] set success [CkBinData_LoadFile $bd $localFilePath] if {$success == 0} then { puts [CkBinData_lastErrorText $bd] delete_CkAi $ai delete_CkBinData $bd exit } set file_id [CkAi_uploadFileBd $ai $bd $filenameOnServer $contentType] if {[CkAi_get_LastMethodSuccess $ai] == 0} then { puts [CkAi_lastErrorText $ai] puts "AI File Upload Failed." } else { puts "File ID: $file_id" puts "File uploaded." } delete_CkAi $ai delete_CkBinData $bd |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.