Illegal base64 character in webcam image

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Illegal base64 character in webcam image

Postby pitc » Fri Feb 05, 2021 10:24 pm

I was attempting to use the webcam package and followed the example as in the webinar (https://www.youtube.com/watch?v=d2ZUVOjmI-w&feature=emb_logo) when I came across this error when trying to save the captured image from the webcam.
In developer the data returned is of type {JSMedia} has these characters at the beginning:
Code: Select all
"data:image/jpeg;base64,/9j/4AA...."

The URI format is data:[<media type>][;base64],<data>
the handler for the capture call back is (where the var is a form var defined as media):
Code: Select all
function getBase64Data_from_webcam_4(data) {
   vf_cam_image = data;
   return;
}

I tried to convert it to a byte array:
Code: Select all
var img_byte_array = utils.base64ToBytes(vf_cam_image)

and get this error message:
exception= java.lang.IllegalArgumentException: Illegal base64 character 3a

The ascii for 3a is the colon (:). I scanned the <data> part and did not find any more.
So does this mean the webcam component is incorrect or is it the utils method that is out of date for JSMedia type?

I am using servoy 2020.12.1 and the latest package: svywebcam (1.0.4)
I have no insight as to how to fix this issue.
Any ideas?
Tom
Tom
prospect-saas.com
pitc
 
Posts: 89
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: Illegal base64 character in webcam image

Postby pitc » Mon Feb 08, 2021 4:29 am

OK so I think I have figured it out.
The prefix has to be ignored. So I take the substring after the comma (",") and then convert to a JSImage then I can store that result to a database table column.
Tom
prospect-saas.com
pitc
 
Posts: 89
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests