svywebcam

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==

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)

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

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

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} */
var bytes = b64.decode(b64Data.split(‘base64,’)[1]);
picture = bytes;
foto = scopes.svyCrypto.base64DecodeAsBytes(b64Data.split(‘base64,’)[1]);
}