I try to upload image from dom element with canvas ( html2canvas.js ). and then i get dataURL() from canvas to upload. Upload is successful but i cant open my file. like a without file extention.
Here my code ;
html2canvas(document.getElementById("wedding1"), {
letterRendering: 1,
allowTaint: true,
onrendered: function(canvas) {
console.log(canvas);
}
}).then(canvas => {
var imageData = canvas.toDataURL("image/png");
imageData.replace(/^data:image\/(png|jpg);base64,/, "");
let canvasImg = document.getElementById("canvasimg");
canvasImg.appendChild(canvas);
this.uploadFile("selam.png", imageData);
});
uploadFile(name, content) {
var createitem = new SP.RequestExecutor(
_spPageContextInfo.webAbsoluteUrl
);
createitem.executeAsync({
url:
_spPageContextInfo.webAbsoluteUrl +
"/_api/web/GetFolderByServerRelativeUrl('/DuyuruDocument')/Files/Add(url='" +
name +
"',overwrite=true)",
method: "POST",
binaryStringRequestBody: true,
body: content,
success: function(e) {
alert("done");
},
error: function() {
alert("Error");
},
state: "Update"
});
},