![]() |
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
(DataFlex) 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.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoAi String sContentType String sLocalFilePath String sFilenameOnServer String sFile_id Variant vBd Handle hoBd String sTemp1 Boolean bTemp1 Move False To iSuccess Get Create (RefClass(cComChilkatAi)) To hoAi If (Not(IsComObjectCreated(hoAi))) Begin Send CreateComObject of hoAi End // Can currently be "openai" or "google" because these are the only AI's that can reference pre-loaded image data by file ID. Set ComProvider Of hoAi To "openai" // Use your provider's API key. Set ComApiKey Of hoAi To "MY_API_KEY" // We can upload directly from a file in the filesystem, or from a Chilkat BinData. Move "image/jpeg" To sContentType Move "qa_data/jpg/starfish.jpg" To sLocalFilePath Move "starfish.jpg" To sFilenameOnServer // Upload directly from a file. Get ComUploadFile Of hoAi sLocalFilePath sContentType To sFile_id Get ComLastMethodSuccess Of hoAi To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoAi To sTemp1 Showln sTemp1 Showln "AI File Upload Failed." End Else Begin Showln "File ID: " sFile_id Showln "File uploaded." End // Upload from the contents of a Chilkat BinData Get Create (RefClass(cComChilkatBinData)) To hoBd If (Not(IsComObjectCreated(hoBd))) Begin Send CreateComObject of hoBd End Get ComLoadFile Of hoBd sLocalFilePath To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoBd To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoBd to vBd Get ComUploadFileBd Of hoAi vBd sFilenameOnServer sContentType To sFile_id Get ComLastMethodSuccess Of hoAi To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoAi To sTemp1 Showln sTemp1 Showln "AI File Upload Failed." End Else Begin Showln "File ID: " sFile_id Showln "File uploaded." End End_Procedure |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.