Sample code for 30+ languages & platforms
VBScript

Upload an Image File to an AI Provider (OpenAI, Google, Antropic, X)

See more AI Examples

Uploads an image file to an AI provider using the provider's File API and returns the id 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.

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

set ai = 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
    outFile.WriteLine(ai.LastErrorText)
    outFile.WriteLine("AI File Upload Failed.")
Else
    outFile.WriteLine("File ID: " & file_id)
    outFile.WriteLine("File uploaded.")
End If

' Upload from the contents of a Chilkat BinData
set bd = CreateObject("Chilkat.BinData")
success = bd.LoadFile(localFilePath)
If (success = 0) Then
    outFile.WriteLine(bd.LastErrorText)
    WScript.Quit
End If

file_id = ai.UploadFileBd(bd,filenameOnServer,contentType)
If (ai.LastMethodSuccess = 0) Then
    outFile.WriteLine(ai.LastErrorText)
    outFile.WriteLine("AI File Upload Failed.")
Else
    outFile.WriteLine("File ID: " & file_id)
    outFile.WriteLine("File uploaded.")
End If


outFile.Close