![]() |
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
(Visual FoxPro) Upload a File to an AI Provider (OpenAI, Google, Antropic, X)See more AI ExamplesUploads a 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, Gemini, Claude, and Grok.Note: This example requires Chilkat v11.4.0 or greater.
LOCAL lnSuccess LOCAL loAi LOCAL lcContentType LOCAL lcLocalFilePath LOCAL lcFilenameOnServer LOCAL lcFile_id LOCAL loSb LOCAL loBd lnSuccess = 0 loAi = CreateObject('Chilkat.Ai') * The provider can be "openai", "google", "claude", "grok", or any AI that supports uploading files for later reference by ID. loAi.Provider = "openai" * Use your provider's API key. loAi.ApiKey = "MY_API_KEY" * We can upload directly from a file in the filesystem, or from a Chilkat StringBuilder, or from a Chilkat BinData. * Some AI providers require a content-type. * Also, some AI providers are picky about what content-type's are accepted. * Check the AI provider's documentation. * "application/json" is generally always acceptable. * "text/plain" can be used as a fallback for any text file. lcContentType = "application/json" lcLocalFilePath = "qa_data/hamlet.json" lcFilenameOnServer = "hamlet.json" * Upload directly from a file. lcFile_id = loAi.UploadFile(lcLocalFilePath,lcContentType) IF (loAi.LastMethodSuccess = 0) THEN ? loAi.LastErrorText ? "AI File Upload Failed." ELSE ? "File ID: " + lcFile_id ? "File uploaded." ENDIF * Upload from the contents of a StringBuilder loSb = CreateObject('Chilkat.StringBuilder') lnSuccess = loSb.LoadFile(lcLocalFilePath,"utf-8") IF (lnSuccess = 0) THEN ? loSb.LastErrorText RELEASE loAi RELEASE loSb CANCEL ENDIF lcFile_id = loAi.UploadFileSb(loSb,lcFilenameOnServer,lcContentType) IF (loAi.LastMethodSuccess = 0) THEN ? loAi.LastErrorText ? "AI File Upload Failed." ELSE ? "File ID: " + lcFile_id ? "File uploaded." ENDIF * Upload from the contents of a BinData loBd = CreateObject('Chilkat.BinData') lnSuccess = loBd.LoadFile(lcLocalFilePath) IF (lnSuccess = 0) THEN ? loBd.LastErrorText RELEASE loAi RELEASE loSb RELEASE loBd CANCEL ENDIF lcFile_id = loAi.UploadFileBd(loBd,lcFilenameOnServer,lcContentType) IF (loAi.LastMethodSuccess = 0) THEN ? loAi.LastErrorText ? "AI File Upload Failed." ELSE ? "File ID: " + lcFile_id ? "File uploaded." ENDIF RELEASE loAi RELEASE loSb RELEASE loBd |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.