svywebcam

Forum to discuss the new web client version of Servoy.

svywebcam

Postby hovw » Wed Jun 06, 2018 11:38 am

We have tried webcamExample

Al works but how to store the caputred base64 image as a normal pjg image in a database.
the problem is convert the base64 data

discription servoy
Finally capture an image using capture. This will capture a shot and if successful data will be returned to the getBase64Data handler.

part off the captiured base64 image
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAG4AoADAREAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL

/Q1jFR0k9Oj6Svq9Fdqzt113GYZeQ5+dXBYc5HGFYE8AkDjqAuRu7tzV9Ffzvb9DGpU5Zyadk7dL7Jd07WuMO1hnZ0OCpO4NjC7jnkZOTjgLnHaqTv5Nbrt21Oj2i5HJe9a2m27tbbp6a2EI4yOu7A3ds/3TjlcLkZxz0Has/humrp2622+/uc0581tLW/HzfmIy7mXCs2AeewBPQnHUcggDJ5+oz0V36X/JAqd4uSertp1dtO+mnl5CDdy2cNtbIPAwDx17nrnnJA4rRJaNve+ln003REk43VrtdLr81dH/2Q==
OSX 10.9.5 - 10.13.1
hovw
 
Posts: 21
Joined: Wed Nov 04, 2009 10:41 pm

Re: svywebcam

Postby hovw » Tue Jun 12, 2018 8:43 am

Code

function callback(data) {
image = data;
var fs_cat = datasources.db.example_data.categories.getFoundSet();
fs_cat.newRecord();
fs_cat.picture = image;
databaseManager.saveData()
}

result

ERROR com.servoy.j2db.util.Debug - Kan data:image/jpeg;base64,/9j/4AAQSkZ..7tau2jP/9k= niet naar media data converteren
at /Users/wim/Documents/TestServoy8_3/ServoyWorkSpace/webCamExample/forms/webcamExample.js:89 (callback)
ERROR com.servoy.j2db.util.Debug - Setting dataprovider with name 'picture', type 'MEDIA' with value of wrong type 'data:image/jpeg;base64,/9j/4AAQS...7tau2jP/9k=' (Form Context: webcamExample)
at /Users/wim/Documents/TestServoy8_3/ServoyWorkSpace/webCamExample/forms/webcamExample.js:89 (callback)
OSX 10.9.5 - 10.13.1
hovw
 
Posts: 21
Joined: Wed Nov 04, 2009 10:41 pm

Re: svywebcam

Postby mboegem » Tue Jun 12, 2018 9:15 am

You are trying to save the b64 string, but you need a byteArray.
No experience with the plugin, but this should work:

Code: Select all
function callback(b64Data) {
   var b64 = new Packages.org.apache.commons.codec.binary.Base64();
   /** @type {Array<byte>} */
   var bytes = b64.decode(b64Data.split('base64,')[1]);

   var fs_cat = datasources.db.example_data.categories.getFoundSet();
   fs_cat.newRecord();
   fs_cat.picture = bytes;
   databaseManager.saveData()
}


If you are using the svyUtils module, you can also find a conversion function for this in the svyCrypto scope: base64DecodeAsBytes
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1426
Joined: Sun Oct 14, 2007 1:34 pm
Location: Hoofddorp, The Netherlands

Re: svywebcam

Postby hovw » Tue Jun 12, 2018 10:04 pm

It works, thanks Marc


form name webcamExample, DataSource example_data.categories.
foto is a new image field.

function callback(data) {
ImageProces(data)
}

function ImageProces(b64Data) {
var b64 = new Packages.org.apache.commons.codec.binary.Base64();
/** @type {Array<byte>} */
var bytes = b64.decode(b64Data.split('base64,')[1]);
picture = bytes;
foto = scopes.svyCrypto.base64DecodeAsBytes(b64Data.split('base64,')[1]);
}
OSX 10.9.5 - 10.13.1
hovw
 
Posts: 21
Joined: Wed Nov 04, 2009 10:41 pm


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 3 guests