Best way to base64encode a jpeg file ?

jbv at souslelogo.com jbv at souslelogo.com
Wed Feb 5 04:22:25 EST 2025


Richard & Mark,

Thank you both for your suggestions.
I actually made some progress, as there were 2 different issues :

1- the syntax of the multimodal json curl must be
   {"type" : "image_url",  "image_url" : {"url": 
"data:image/jpeg;base64,{_BASE64_}"}}
instead of
   {"type" : "image_url",  "image_url" : {"url": "data:image/jpeg;base64 
{_BASE64_}"}}
I found the tip in an obscure blog post from early 2023.
Even the latest ChatGPT-4o3 missed the point.

2- I still have a problem with the base64 encoding of a jpeg file in LC.
Long story short, I am trying to send a curl request to a vision AI 
model running with
LM studio. I tried several models that didn't give much details in the 
error messages,
except for "bad request" or "data must be base64 encoded jpeg".
But the last one I tried returned :
{"error":"Input buffer has corrupt header: VipsJpeg: Corrupt JPEG data: 
13 extraneous bytes before marker 0x8e\nVipsJpeg: Unsupported marker 
type 0x8e"}

Here is my code for base64 encoding :
   put URL ("file:" & "myfile.jpg") into timagedata
   put base64encode(timagedata) into tBase64Image
   replace return with "" in tBase64Image

Thanks,
jbv



More information about the use-livecode mailing list