NetTalk Central

Author Topic: Load image in browse (base64)  (Read 6030 times)

agustinh2000

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Email
Load image in browse (base64)
« on: January 16, 2019, 09:10:13 AM »
Hi!

I have string that I receive from the device (image base64 Camera.DestinationType.DATA_URL), When I want to see it directly in the browse (image field type) the string is broken ...
for example

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD....(in field)

data:image/jpeg%3Bbase64%2C/9j/4AAQSkZJRgABAQAAAQABAAD...(
inspect element in web browser)..

Any idea how to solve it? (stringtheory, etc.)

thanks!

Agust

Jane

  • Sr. Member
  • ****
  • Posts: 372
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: Load image in browse (base64)
« Reply #1 on: January 16, 2019, 09:24:07 AM »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Load image in browse (base64)
« Reply #2 on: January 17, 2019, 01:15:35 AM »
>> data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD

so the clues are here, ys. It's an image, encoded as base 64.
So you need to get the "data" part (I'm guessing it's everything after the comma) then Base64Decode it (using StringTheory) and you have the "raw jpeg" image.

The easiest way to serve it is to give it a name, same it to disk (somewhere under the web folder) and then use that name in an image control on the form.

Cheers
bruce

agustinh2000

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Email
Re: Load image in browse (base64)
« Reply #3 on: January 17, 2019, 06:27:30 AM »
Something like that..


str.SetValue(clip("data" part))
if str.Length()
  str.Base64Decode()

end

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Load image in browse (base64)
« Reply #4 on: January 18, 2019, 01:48:14 AM »
something like;

str.SetValue(clip("data part"))
str.SetValue(str.after(','))
str.base64Decode()
str.SaveFile('whatever.jpg')


agustinh2000

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Email
Re: Load image in browse (base64)
« Reply #5 on: January 18, 2019, 07:18:19 AM »
It works perfect, thank you very much!