Re: Best way to base64encode a jpeg file ?

2025-02-05 Thread jbv via use-livecode

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

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Best way to base64encode a jpeg file ?

2025-02-05 Thread Monte Goulding via use-livecode
Hi jbv

> Here is my code for base64 encoding :
>  put URL ("file:" & "myfile.jpg") into timagedata

Use `binfile:` here instead of `file:` so the engine doesn’t treat the data as 
native text and fiddle with it

>  put base64encode(timagedata) into tBase64Image
>  replace return with "" in tBase64Image

You need url safe base64 encoding so you need:

local tEncoded
put base64Encode(pData) into tEncoded
replace return with empty in tEncoded
replace "+" with "-" in tEncoded
replace "/" with "_" in tEncoded
replace "=" with empty in tEncoded

> 
> Thanks,
> jbv
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Best way to base64encode a jpeg file ?

2025-02-05 Thread Bob Sneidar via use-livecode
I’m curious whether or not this solution worked…

Bob S


> On Feb 5, 2025, at 1:35 AM, Monte Goulding via use-livecode 
>  wrote:
> 
> Hi jbv
> 
>> Here is my code for base64 encoding :
>> put URL ("file:" & "myfile.jpg") into timagedata
> 
> Use `binfile:` here instead of `file:` so the engine doesn’t treat the data 
> as native text and fiddle with it
> 
>> put base64encode(timagedata) into tBase64Image
>> replace return with "" in tBase64Image
> 
> You need url safe base64 encoding so you need:
> 
> local tEncoded
> put base64Encode(pData) into tEncoded
> replace return with empty in tEncoded
> replace "+" with "-" in tEncoded
> replace "/" with "_" in tEncoded
> replace "=" with empty in tEncoded
> 
>> 
>> Thanks,
>> jbv
>> 
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


RE: Best way to base64encode a jpeg file ?

2025-02-05 Thread Ralph DiMola via use-livecode
I can see getting rid of extraneous CRs or LFs but aren’t "+","/" and "=" part 
of the encoding and corrupt the base 64 data stream? Or am I missing something?

Ralph DiMola
IT Director
Evergreen Information Services
rdim...@evergreeninfo.net

-Original Message-
From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf Of 
Monte Goulding via use-livecode
Sent: Wednesday, February 05, 2025 4:36 AM
To: How to use LiveCode
Cc: Monte Goulding
Subject: Re: Best way to base64encode a jpeg file ?

Hi jbv

> Here is my code for base64 encoding :
>  put URL ("file:" & "myfile.jpg") into timagedata

Use `binfile:` here instead of `file:` so the engine doesn’t treat the data as 
native text and fiddle with it

>  put base64encode(timagedata) into tBase64Image  replace return with 
> "" in tBase64Image

You need url safe base64 encoding so you need:

local tEncoded
put base64Encode(pData) into tEncoded
replace return with empty in tEncoded
replace "+" with "-" in tEncoded
replace "/" with "_" in tEncoded
replace "=" with empty in tEncoded

> 
> Thanks,
> jbv
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode