Move78 Fiddle

ASBLI Move78 Fiddle

by Mohit Agrawal

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>
<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>
<input type="file" onchange="encodeImageFileAsURL(this)" />

JavaScript

var imageStr = '';

function prepareInput() {
	var req =  {
    "message": imageStr,
    "filename": 'abc',
    "document_type": ""
    };
    
    return req;
};

var callService = function(imgStr) {
 /* console.log("imgStr: " + imgStr) */;

  $(document).ready(function () {
     $.ajax({
        type: 'POST',
        contentType: 'application/json',
        url: '',
        data: prepareInput(),
        success: function(data, textStatus, jqXHR){ 
          console.log('Success --> ' + data);
          },
        error: function(jqXHR, textStatus, errorThrown){ 
          console.log('Error -->' + textStatus); 
          }
      });
  });
 
}

var aesEncrypt = function(message = '', key = ''){
    var message = CryptoJS.AES.encrypt(message, key);
  	imageStr = message.toString();
    callService();
};

function encodeImageFileAsURL(element) {
  var file = element.files[0];
  var reader = new FileReader();
  reader.onloadend = function() {
    /* console.log('RESULT', reader.result) */;
    
    aesEncrypt(reader.result);
  }
  reader.readAsDataURL(file);
}