Save a base 64 image from URL

1

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()
    
asked by ElTío 04.07.2017 в 21:07
source

2 answers

1

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
answered by 05.07.2017 в 14:38
0

I found a link from the Genexus documentation itself, where you can get or generate a Blob file in base64:

  • ToBase64String (): Returns the contents of the Blob file in Base64.
  • FromBase64String (): loads the content in Base64 received by the parameters in the Blob file.

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.

    
answered by 04.07.2017 в 23:55