![]() |
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
(Unicode C++) 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.
#include <CkAiW.h> #include <CkBinDataW.h> void ChilkatSample(void) { bool success = false; CkAiW ai; // Can currently be "openai" or "google" because these are the only AI's that can reference pre-loaded image data by file ID. ai.put_Provider(L"openai"); // Use your provider's API key. ai.put_ApiKey(L"MY_API_KEY"); // We can upload directly from a file in the filesystem, or from a Chilkat BinData. const wchar_t *contentType = L"image/jpeg"; const wchar_t *localFilePath = L"qa_data/jpg/starfish.jpg"; const wchar_t *filenameOnServer = L"starfish.jpg"; // Upload directly from a file. const wchar_t *file_id = ai.uploadFile(localFilePath,contentType); if (ai.get_LastMethodSuccess() == false) { wprintf(L"%s\n",ai.lastErrorText()); wprintf(L"AI File Upload Failed.\n"); } else { wprintf(L"File ID: %s\n",file_id); wprintf(L"File uploaded.\n"); } // Upload from the contents of a Chilkat BinData CkBinDataW bd; success = bd.LoadFile(localFilePath); if (success == false) { wprintf(L"%s\n",bd.lastErrorText()); return; } file_id = ai.uploadFileBd(bd,filenameOnServer,contentType); if (ai.get_LastMethodSuccess() == false) { wprintf(L"%s\n",ai.lastErrorText()); wprintf(L"AI File Upload Failed.\n"); } else { wprintf(L"File ID: %s\n",file_id); wprintf(L"File uploaded.\n"); } } |
||||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.