Issue reading file using  JavaScript and save it to Database
Application Type
Service Studio Version
11.54.29 (Build 62891)

I am trying to read file using JavaScript (readAsBinaryString) and save it to database as bindary data .I am not  going to use Outsystem upload widget .

My goal is to read the file  as Binary data and save to database in small chunk/part .  (For large File) 

problem : The problem is that Binary vairable  that hold file in chunk(part) shows some bytes( like 50000 byte) on client action but that  same varible I send server action  as input it show (o bytes). So some where Binary data lost from client action to server actoin .

I read file  using  var fileInput =document.getElementById($parameters.UploadFileId).fileInput.files[0]  and use readAsBinaryString reader to read binary string  and divide in chunk (part)  then call a clientaciton $actions.SendChunkDataToServer(slice)  and send that chunk variable over client action. 

When I debug I can see in that client action  it show some binary data (50000 bytes) but When I send this input to server action it start showing (o bytes) .

I have attached detail code of JavaScript  in as attachment .Also attaching video of debugging 

JavaScript code like that

var UploadElement =document.getElementById($parameters.UploadFileId);

UploadElement.addEventListener('change', function(){


       var fileInput =document.getElementById($parameters.UploadFileId);


        console.log('Trying to upload the video file: %O', fileInput);

        if ('files' in fileInput) {

            if (fileInput.files.length === 0) {

                alert("Select a file to upload");

            } else {



        } else {

            console.log('No found "files" property');



 var fileInput =document.getElementById($parameters.UploadFileId);


function UploadVideo(file) {

    var loaded = 0;

    var chunkSize = 500000;

    var total     = file.size;

    var reader    = new FileReader();

    var slice = file.slice(0, chunkSize);


    // Reading a chunk to invoke the 'onload' event

     console.log('Started uploading file "' + file.name + '"');


    reader.onload = function (e) {

        //Just simulate API

         console.log("Slice Data")



          loaded += chunkSize;

          var percentLoaded = Math.min((loaded / total) * 100, 100);

          console.log('Uploaded ' + Math.floor(percentLoaded) + '% of file "' + file.name + '"');

         // $('#uploadVideoProgressBar').width(percentLoaded + "%");

          //Read the next chunk and call 'onload' event again

          if (loaded <= total) {

              slice = file.slice(loaded, loaded + chunkSize);


          } else { 

              loaded = total;

            console.log('File "' + file.name + '" uploaded successfully!');








There is already a Forge component that splits a file in smaller chunks and uploads them, created by the number #1 Forge component creator and MVP Miguel Antunes.





I had this problem before.

The problem is Outsystems can't read the binary data from readAsBinaryString() function. I don't know why . My guess is Binary data and Blob data type are different.

Here is what i did to overcome.

I convert to base64 using readAsDataURL(), File data now is text, chunk it and send it to server then convert back to binary.

Here is my js for upload for your reference.

function readAndSend(file) {

    var reader = new FileReader();

    reader.addEventListener('load', function() {

        var startOfOSBinary = this.result.indexOf(";base64,") + 8;

        var lengthOSBinary = this.result.length - startOfOSBinary;

        var OSbinary = this.result.substr(startOfOSBinary, lengthOSBinary);

        $actions.TriggerFileUpload(file.name, file.size, file.type, OSbinary);

    }, false);



var fileInput = document.getElementById($parameters.FileInputId);

var files = Array.from(fileInput.files);

if (files) {

    for (var i = 0; i < files.length; i++) {



} else {

    $actions.TriggerFileUploadError("", "", "Uploading files is disabled");


fileInput.value = "";

I define TriggerFileUpload action for handling the file . OSBinary is a whole file as text, so i chunk it then send to server then convert back to binary.

I used this to upload large image and video too.

Hope it help.

Cheers, Nam

Thanks  @Nam Nguyen  for your reply  Yes Outsystems does not recognizing  JavaScript  Blob data . Converting base64 is last solution I am thinking  

Base64   working my side too .Actually I don't want to convert  binary to base64  and re convert to base64 to binary sever side   because it put extra overhead  if there is large big  fine .

If there is someway we can send directly binary data to server side 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.