Help converting python one-liner...

2024-04-25 Thread Niggemann, Bernd via use-livecode
Hi David,

Are you sure that sImage contains the data you want?

What happens if instead of:

put url imageUrl into sImage

you do: put url("binfile:" & imageURL) into sImage

Kind regards
Bernd





___
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: Help converting python one-liner...

2024-04-25 Thread Bob Sneidar via use-livecode
Well the good news (I suppose) is that base64Decode seems to ignore the 
carriage returns in the encoded string. The bad news (for me) is that it means 
my intermittence issue had nothing to do with the carriage returns. 

Bob S


> On Apr 25, 2024, at 8:09 AM, Bob Sneidar via use-livecode 
>  wrote:
> 
> Wha THAT may be why I was getting intermittent success with a socket 
> based file transfer utility I developed! I wonder what base64Decode does with 
> a base64Encoded string if you remove the carriage returns first? I’m going to 
> have to research that. 
> 
> Bob S
> 
> 
>> On Apr 25, 2024, at 7:57 AM, Andreas Bergendal via use-livecode 
>>  wrote:
>> 
>> The problem may be that base64 encoding inserts line breaks after every 76
>> chars (a remnant from terminal monitor width restrictions, apparently).
>> I ran into this a while ago, and cleaning the encoded string with “replace
>> cr with empty in tString” solved it for me.
>> I don’t think any textEncode/Decode should be needed after that (Python is
>> a different animal after all… :)
>> 
>> /Andreas
>> 

___
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: Help converting python one-liner...

2024-04-25 Thread Bob Sneidar via use-livecode
Wha THAT may be why I was getting intermittent success with a socket 
based file transfer utility I developed! I wonder what base64Decode does with a 
base64Encoded string if you remove the carriage returns first? I’m going to 
have to research that. 

Bob S


> On Apr 25, 2024, at 7:57 AM, Andreas Bergendal via use-livecode 
>  wrote:
> 
> The problem may be that base64 encoding inserts line breaks after every 76
> chars (a remnant from terminal monitor width restrictions, apparently).
> I ran into this a while ago, and cleaning the encoded string with “replace
> cr with empty in tString” solved it for me.
> I don’t think any textEncode/Decode should be needed after that (Python is
> a different animal after all… :)
> 
> /Andreas
> 
> ons 24 apr. 2024 kl. 20:46 skrev David Bovill via use-livecode <
> use-livecode@lists.runrev.com>:
> 
>> I need to put encodeImageData into json (which is utf-8) and then post it
>> to the api. I'm not sure what aspects of base64 encoding would not be utf8
>> compatible... seem to remember there are some quirks there to be aware of.
>> The python code does  the decode("utf-8") step at the end - so I guess
>> there is some issue with raw base64 encoding in json?
>> 
>> On Wed, 24 Apr 2024 at 19:26, Paul Dupuis via use-livecode <
>> use-livecode@lists.runrev.com> wrote:
>> 
>>> On 4/24/2024 1:43 PM, David Bovill via use-livecode wrote:
 I'm trying to base64 encode an image and include it into a json file to
 post to an api. The python code that accomplishes this is:
 
 image1_data =
 base64.b64encode(httpx.get(image1_url).content).decode("utf-8")
 
 When I try to follow the logic in Livecode I get:
 
 put url imageUrl into sImage
 put base64Encode (sImage) into base64Image
 put textDecode (base64Image, "UTF-8") into encodedImageData
 
 However the api complains that the image is not encoded properly.
>> Adding
>>> or
 removing the "textDecode" step does not help. Any thoughts?
 
>>> 
>>> This is just a guess, but I thing your last line needs to be:
>>> 
>>> put textEncode(base64Image,"UTF-8") into encodedImageData
>>> 
>>> textDecode in Livecode converts from the format (UTF-8) to Livecode's
>>> 16bit internal unicode
>>> 
>>> textEncode converts from livecode's internal 16bit unicode to the
>>> indicated format (UTF-8).
>> 
> ___
> 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: Help converting python one-liner...

2024-04-25 Thread Andreas Bergendal via use-livecode
The problem may be that base64 encoding inserts line breaks after every 76
chars (a remnant from terminal monitor width restrictions, apparently).
I ran into this a while ago, and cleaning the encoded string with “replace
cr with empty in tString” solved it for me.
I don’t think any textEncode/Decode should be needed after that (Python is
a different animal after all… :)

/Andreas

ons 24 apr. 2024 kl. 20:46 skrev David Bovill via use-livecode <
use-livecode@lists.runrev.com>:

> I need to put encodeImageData into json (which is utf-8) and then post it
> to the api. I'm not sure what aspects of base64 encoding would not be utf8
> compatible... seem to remember there are some quirks there to be aware of.
> The python code does  the decode("utf-8") step at the end - so I guess
> there is some issue with raw base64 encoding in json?
>
> On Wed, 24 Apr 2024 at 19:26, Paul Dupuis via use-livecode <
> use-livecode@lists.runrev.com> wrote:
>
> > On 4/24/2024 1:43 PM, David Bovill via use-livecode wrote:
> > > I'm trying to base64 encode an image and include it into a json file to
> > > post to an api. The python code that accomplishes this is:
> > >
> > > image1_data =
> > > base64.b64encode(httpx.get(image1_url).content).decode("utf-8")
> > >
> > > When I try to follow the logic in Livecode I get:
> > >
> > > put url imageUrl into sImage
> > > put base64Encode (sImage) into base64Image
> > > put textDecode (base64Image, "UTF-8") into encodedImageData
> > >
> > > However the api complains that the image is not encoded properly.
> Adding
> > or
> > > removing the "textDecode" step does not help. Any thoughts?
> > >
> >
> > This is just a guess, but I thing your last line needs to be:
> >
> > put textEncode(base64Image,"UTF-8") into encodedImageData
> >
> > textDecode in Livecode converts from the format (UTF-8) to Livecode's
> > 16bit internal unicode
> >
> > textEncode converts from livecode's internal 16bit unicode to the
> > indicated format (UTF-8).
>
___
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: Help converting python one-liner...

2024-04-24 Thread Paul Dupuis via use-livecode

If json need utf8, then the last line needs to be:

put textEncode(base64Image,"UTF-8") into encodedImageData

textEncode will convert the bas64 data (stored in livecode as 16bit characters) 
to UTF8

On 4/24/2024 2:45 PM, David Bovill via use-livecode wrote:

I need to put encodeImageData into json (which is utf-8) and then post it
to the api. I'm not sure what aspects of base64 encoding would not be utf8
compatible... seem to remember there are some quirks there to be aware of.
The python code does  the decode("utf-8") step at the end - so I guess
there is some issue with raw base64 encoding in json?

On Wed, 24 Apr 2024 at 19:26, Paul Dupuis via use-livecode <
use-livecode@lists.runrev.com> wrote:


On 4/24/2024 1:43 PM, David Bovill via use-livecode wrote:

I'm trying to base64 encode an image and include it into a json file to
post to an api. The python code that accomplishes this is:

image1_data =
base64.b64encode(httpx.get(image1_url).content).decode("utf-8")

When I try to follow the logic in Livecode I get:

put url imageUrl into sImage
put base64Encode (sImage) into base64Image
put textDecode (base64Image, "UTF-8") into encodedImageData

However the api complains that the image is not encoded properly. Adding

or

removing the "textDecode" step does not help. Any thoughts?


This is just a guess, but I thing your last line needs to be:

put textEncode(base64Image,"UTF-8") into encodedImageData

textDecode in Livecode converts from the format (UTF-8) to Livecode's
16bit internal unicode

textEncode converts from livecode's internal 16bit unicode to the
indicated format (UTF-8).
___
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: Help converting python one-liner...

2024-04-24 Thread David Bovill via use-livecode
I need to put encodeImageData into json (which is utf-8) and then post it
to the api. I'm not sure what aspects of base64 encoding would not be utf8
compatible... seem to remember there are some quirks there to be aware of.
The python code does  the decode("utf-8") step at the end - so I guess
there is some issue with raw base64 encoding in json?

On Wed, 24 Apr 2024 at 19:26, Paul Dupuis via use-livecode <
use-livecode@lists.runrev.com> wrote:

> On 4/24/2024 1:43 PM, David Bovill via use-livecode wrote:
> > I'm trying to base64 encode an image and include it into a json file to
> > post to an api. The python code that accomplishes this is:
> >
> > image1_data =
> > base64.b64encode(httpx.get(image1_url).content).decode("utf-8")
> >
> > When I try to follow the logic in Livecode I get:
> >
> > put url imageUrl into sImage
> > put base64Encode (sImage) into base64Image
> > put textDecode (base64Image, "UTF-8") into encodedImageData
> >
> > However the api complains that the image is not encoded properly. Adding
> or
> > removing the "textDecode" step does not help. Any thoughts?
> >
>
> This is just a guess, but I thing your last line needs to be:
>
> put textEncode(base64Image,"UTF-8") into encodedImageData
>
> textDecode in Livecode converts from the format (UTF-8) to Livecode's
> 16bit internal unicode
>
> textEncode converts from livecode's internal 16bit unicode to the
> indicated format (UTF-8).
> ___
> 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: Help converting python one-liner...

2024-04-24 Thread Paul Dupuis via use-livecode

On 4/24/2024 1:43 PM, David Bovill via use-livecode wrote:

I'm trying to base64 encode an image and include it into a json file to
post to an api. The python code that accomplishes this is:

image1_data =
base64.b64encode(httpx.get(image1_url).content).decode("utf-8")

When I try to follow the logic in Livecode I get:

put url imageUrl into sImage
put base64Encode (sImage) into base64Image
put textDecode (base64Image, "UTF-8") into encodedImageData

However the api complains that the image is not encoded properly. Adding or
removing the "textDecode" step does not help. Any thoughts?



This is just a guess, but I thing your last line needs to be:

put textEncode(base64Image,"UTF-8") into encodedImageData

textDecode in Livecode converts from the format (UTF-8) to Livecode's 
16bit internal unicode


textEncode converts from livecode's internal 16bit unicode to the 
indicated format (UTF-8).

___
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


Help converting python one-liner...

2024-04-24 Thread David Bovill via use-livecode
I'm trying to base64 encode an image and include it into a json file to
post to an api. The python code that accomplishes this is:

image1_data =
base64.b64encode(httpx.get(image1_url).content).decode("utf-8")

When I try to follow the logic in Livecode I get:

put url imageUrl into sImage
put base64Encode (sImage) into base64Image
put textDecode (base64Image, "UTF-8") into encodedImageData

However the api complains that the image is not encoded properly. Adding or
removing the "textDecode" step does not help. Any thoughts?
___
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