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

1 Answer 1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.