Hello Experts,
For choosing the image and uploading to the thumbnail in ms crm i have wriiten Html and javascript , i don't now how to resize the image to 144* 144 pixel to fit exactly in the tumbnail please suggest me below is my html and javascript code.please suggest me i am new to html and javascrpit.
<html><head>
<meta>
<meta>
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<meta><meta></head>
<body onfocusout="parent.setEmailRange();" style="overflow-wrap: break-word;">
<input type="file" id="fileUpload">
<input type="button" id="upload" value="Upload" onclick="Upload(event)">
<script src="sonade_/Scripts/SDK.REST.js" type="text/javascript"></script>
<script src="sonade_ImageUpload.js" type="text/javascript"></script>
</body></html>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var Cnt = 0;
var index = 0;
var id = null;
function Upload() {
debugger;
id = window.parent.Xrm.Page.data.entity.getId();
var fileUpload = document.getElementById("fileUpload");
var ufiles = fileUpload.files;
nfiles = ufiles;
Cnt = ufiles.length;
sendFile();
}
function _arrayBufferToBase64(buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
function sendFile() {
if (index < Cnt) {
var reader = new FileReader();
reader.onload = function (evt) {
var str = _arrayBufferToBase64(reader.result);
var tt = 'data:image/png;base64,'
document.getElementById("form_pic_image").src = tt + str;
console.log( nfiles[index].name, nfiles[index].type, '--->1');
SaveImage(str, nfiles[index].name, nfiles[index].type);
}
reader.readAsArrayBuffer(nfiles[index]);
}
}
function SaveImage(docBody, fName, mType) {
var entity = {};
if (docBody != null) {
entity.EntityImage = docBody;
UpdateEntities(id, entity, 'Product');
}
else {
loading.close();
alert('something wrong..!');
}
}
function UpdateEntities(EntityID, EntityFields, EntityName) {
var ContactEntity = {};
ContactEntity = EntityFields;
SDK.REST.updateRecord(
EntityID,
EntityFields,
EntityName,
function () {
alert("Successfully updated.");
//document.getElementById("form_pic_image").style.width = "100%";
//document.getElementById("form_pic_image").style.height = "100%";
},
function (error) {
alert(error.message);
}
);
}