update record setBinaryFieldValue clientside - Forum - Rollbase - Progress Community

update record setBinaryFieldValue clientside

 Forum

update record setBinaryFieldValue clientside

This question is not answered

hi Rollbase Team,

I am looking for an option to clientside update an image upload field.

Below my function:

function readAndSave(file) {


if ( /\.(jpe?g|png|gif)$/i.test(file.name) ) {

var reader = new FileReader();

reader.addEventListener("load", function () {
var image = new Image();
window.imageinfo = image;
//image.height = 100;
image.title = file.name;
image.src = this.result;

var v_imagefile = image.src;

var v_updateArr = { "odossierp_image1" : image.src }

rbf_updateRecord("odossier", v_recordid, v_updateArr, false, function callback(result){
console.log("result " + result);
}, false);

}, false);

reader.readAsDataURL(file);
}

}

The update record returns an Error 400 (Bad request)

Can anybody help me with this?

Regards Jorrit

All Replies
  • Don't think you can do it like that. You could create an idea (product enhancement) for this. Basically a client-side API that supports updating of binary fields.
    However, what you could do is:

    • Get the Binary64 value of the image you want to put into the image upload field
    • Store this value in a hidden Text field
    • Store the MIME type and Image name in fields as well
    • Run a trigger (object script) using the client-side API that uses the value of the text field (B64) to run the server-side setBinaryFieldValue API

    That should update the image upload field accordingly. There is no direct way of manipulating the image (upload) field from client-side code.

    Client-Side code

    <script>
      	//Whatever function to get the B64 value of the image
      	//Plus add a function (and fields) to also store MIME-type and possibly filename (because the server-side api needs those as well)
      	function setDescriptionFieldToB64() {
      		var binary64 = 'iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAA21BMVEX////DAC/dADHQADDdAC7BACXDAC3cACjCACrdAC3eHj3FHjvCACjbABvVa3zAABrBACDbABXna33cACS/ABHcACbKN1DhN1LcACG+AADbABHbABn+9vi/AA/bAA3AAB364ubtw8ry0dbysrv1xMvlqbLgJEXdjJjtlKDwqLLqhZL67fDzusL+9/nlWm7eCDfjSWDag47pd4fOSmD35Obosrr52t/Yc4LjnafIJ0XgLkz3z9bskZ3NR13TVWrKMkzSYG/qfY3jRFzkUmjmYHPfGj/fl5/LAADXeob1TPQbAAAL/klEQVR4nO2de1/aShe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3ljax/tMkkKzh7w0lvpsDV9LkENO0AOSks5gSHiSjoX8+rpI6iONm2SglyLbKuLHMxIKUa95A6nPcKQJBB5yUnypAxI7ppOehmTsQn6BSGSf4XtcwvdehCQuhyc+78mAwMxnXeEOYDrbW/WJVoKPgT8O3UDss5xHy6Kw1OKe//p8/tNm0Mig0HTuVvXgp+FrlXyMIlmhaWX5037JqEo9oY6o0Kz1uBr0RYyrNMehKTSct9U/Ym7yQno2C0VhpfdrBUMZhOklwXL0FZrO3vqeaDk81rYcXYUrNhjIqKhpOXoKzRrbDiBpzn/qWY6WwrUYDGRS17EcDYWV1u/1GAxkemkrW46yQtN52OQjc4evHUXLUVToGgxnV6cORzk1y1F7HnDNWLvBIPy0VY6VUFFo9L5twmAg3au2vOXIK6y0drfnCeuDZ+lRjqzCkvOw4sfGKnL/w5azHDmFprWzJQ9WDyFpOTIKzUODv6TNwWlVwnIkFBq9k+0wGEj3KvmJs4kKK70tMhjI4DmpXpVUEe5tmcFA7vfjLSdWoWndbZ/BQFzL0etU2FqDgZw2xJYT0zFkraQIuhq6T0LLESnccoOBDF4EloMrLPWuB5t+y8oILAdTaDofwmAgZxdIvQoqNA9L660xcTJqgpEcUFizOHfZrZ3uuN+MVVhp3X4sg4FMXtri01tK6ypir5bpfrheFTknamWrZOsmvCoXOnNvzUXs1bK0nEBhzdqGGhMj52O7GVJotN6YDgTcIiZ1fySX/3sMBjL1GgHyrsE8/i0GAxked/LWDu+ms21jVP7LDCYlJSUlJSUlJSUlJSUlJWVN/B8nyTHKuU+ErgAAAABJRU5ErkJggg==';
     		rbf_setField('Artikel', {!id}, 'Artikelomschrijving', binary64, false, function callback(result) {
        		console.log(result);
            }, false);
      
    	}
    
    	UpdateImageUploadField();
    	//Probably perform some check if this field is actually in use/filled
    	rbf_runTrigger('Artikel', {!id}, 'desc2img', false, function callback(result) { console.log(result); }, false);
    
    </script>

     

    Trigger

    rbv_api.setBinaryFieldValue('Artikel', {!id}, 'Artikelafbeelding', '{!Artikelomschrijving}', 'image/png', 'ruben');