In Genexus15, I can not save an image from a URL to pass it to base 64.
&image.ImageURI = 'unaURLCualquiera'
&url = &image.ImageURI
&blob.FromString(&url)
&blob.ToBase64String()
In Genexus15, I can not save an image from a URL to pass it to base 64.
&image.ImageURI = 'unaURLCualquiera'
&url = &image.ImageURI
&blob.FromString(&url)
&blob.ToBase64String()
The way to convert an image to a string in base 64 is through a Blob
as you are doing, but the problem is how the Blob
is loaded.
There is no way to allocate a variable of type Blob
in memory, the Blob
has to be loaded from the file system . A possible solution is to save the image in a temporary directory and upload it to Blob
using the FromString
method.
With this code I managed to make it work:
Event 'ToBase64'
&httpclient.Execute('GET', &image.ImageURI)
&tmpFile = Directory.TemporaryFilesPath + 'temp.png'
&httpclient.ToFile(&tmpFile)
&blob.FromString(&tmpFile)
&base64Str = &blob.ToBase64String()
Endevent
where:
&image
is of type Image
, &httpclient
is of type HttpClient
, &tmpFile
is of type VarChar
, &blob
is of type Blob
, and &base64Str
is of type LongVarChar
I found a link from the Genexus documentation itself, where you can get or generate a Blob file in base64:
And you use it in the following way:
ContentBase64 = <att | var>.ToBase64String()
<att | var>.FromBase64String(ContentBase64)
ContentBase64 contains Base64 and could be a LongVarChar, for example.
Until now, when a Web service with a returning Blob parameter is called, the value returned will be the Blob file in Base64.
ContentBase64 = WebServiceBlob.Execute()
I hope my little help will help you. Greetings.