0

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"
  });
},
  • Is there any specific reason you have used "SP.RequestExecutor" ? – harshal gite Oct 10 at 11:06
  • no, anyway doing that other way sir ? – Mert Oct 10 at 11:18
0

i solve that problem. It has to be raw ! here my codes ;

   function convertDataURIToBinary(dataURI) {
  var BASE64_MARKER = ";base64,";
  var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
  var base64 = dataURI.substring(base64Index);
  var raw = window.atob(base64);
  return raw;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.