![]() |
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
(Classic ASP) 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.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% success = 0 set ai = Server.CreateObject("Chilkat.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.Provider = "openai" ' Use your provider's API key. ai.ApiKey = "MY_API_KEY" ' We can upload directly from a file in the filesystem, or from a Chilkat BinData. contentType = "image/jpeg" localFilePath = "qa_data/jpg/starfish.jpg" filenameOnServer = "starfish.jpg" ' Upload directly from a file. file_id = ai.UploadFile(localFilePath,contentType) If (ai.LastMethodSuccess = 0) Then Response.Write "<pre>" & Server.HTMLEncode( ai.LastErrorText) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "AI File Upload Failed.") & "</pre>" Else Response.Write "<pre>" & Server.HTMLEncode( "File ID: " & file_id) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "File uploaded.") & "</pre>" End If ' Upload from the contents of a Chilkat BinData set bd = Server.CreateObject("Chilkat.BinData") success = bd.LoadFile(localFilePath) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( bd.LastErrorText) & "</pre>" Response.End End If file_id = ai.UploadFileBd(bd,filenameOnServer,contentType) If (ai.LastMethodSuccess = 0) Then Response.Write "<pre>" & Server.HTMLEncode( ai.LastErrorText) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "AI File Upload Failed.") & "</pre>" Else Response.Write "<pre>" & Server.HTMLEncode( "File ID: " & file_id) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "File uploaded.") & "</pre>" End If %> </body> </html> |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.