PowerBuilder
PowerBuilder
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 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.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ai
string ls_ContentType
string ls_LocalFilePath
string ls_FilenameOnServer
string ls_File_id
oleobject loo_Bd
li_Success = 0
loo_Ai = create oleobject
li_rc = loo_Ai.ConnectToNewObject("Chilkat.Ai")
if li_rc < 0 then
destroy loo_Ai
MessageBox("Error","Connecting to COM object failed")
return
end if
// Can currently be "openai" or "google" because these are the only AI's that can reference pre-loaded image data by file ID.
loo_Ai.Provider = "openai"
// Use your provider's API key.
loo_Ai.ApiKey = "MY_API_KEY"
// We can upload directly from a file in the filesystem, or from a Chilkat BinData.
ls_ContentType = "image/jpeg"
ls_LocalFilePath = "qa_data/jpg/starfish.jpg"
ls_FilenameOnServer = "starfish.jpg"
// Upload directly from a file.
ls_File_id = loo_Ai.UploadFile(ls_LocalFilePath,ls_ContentType)
if loo_Ai.LastMethodSuccess = 0 then
Write-Debug loo_Ai.LastErrorText
Write-Debug "AI File Upload Failed."
else
Write-Debug "File ID: " + ls_File_id
Write-Debug "File uploaded."
end if
// Upload from the contents of a Chilkat BinData
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_Bd.LoadFile(ls_LocalFilePath)
if li_Success = 0 then
Write-Debug loo_Bd.LastErrorText
destroy loo_Ai
destroy loo_Bd
return
end if
ls_File_id = loo_Ai.UploadFileBd(loo_Bd,ls_FilenameOnServer,ls_ContentType)
if loo_Ai.LastMethodSuccess = 0 then
Write-Debug loo_Ai.LastErrorText
Write-Debug "AI File Upload Failed."
else
Write-Debug "File ID: " + ls_File_id
Write-Debug "File uploaded."
end if
destroy loo_Ai
destroy loo_Bd