Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaJavaScriptNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

VBScript Examples
Web API Categories

AI
ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
JavaScript
MHT / HTML Email
MIME
Markdown
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

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

See more AI Examples
Uploads a 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, Gemini, Claude, and Grok.

Note: This example requires Chilkat v11.4.0 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

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")

' The provider can be "openai", "google", "claude", "grok", or any AI that supports uploading files for later reference by 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 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.
contentType = "application/json"
localFilePath = "qa_data/hamlet.json"
filenameOnServer = "hamlet.json"

' 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 StringBuilder
set sb = CreateObject("Chilkat.StringBuilder")
success = sb.LoadFile(localFilePath,"utf-8")
If (success = 0) Then
    outFile.WriteLine(sb.LastErrorText)
    WScript.Quit
End If

file_id = ai.UploadFileSb(sb,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

' Upload from the contents of a 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

 

© 2000-2026 Chilkat Software, Inc. All Rights Reserved.