I need to let the image created by web auto save and post to google drive's folder by using doPost(e). I already deploy this web on google app script,but I don't know how to insert the 'post' function in my html code.
Here is image created and save part of my html code.
<script src="./plugin/canvas-sign.js"></script>
<script>
/*
let width = Dimensions.get("screen").width;
let height = Dimensions.get("screen").height;
*/
/*
var screenwidth = (window.innerWidth > 0) ? window.innerWidth : screen.width;
var screenheight = (window.innerHeight > 0) ? window.innerHeight : screen.height;
*/
let cv = document.getElementById("canvas");
let rect = document.getElementById("app").getBoundingClientRect();
cv.width = screenwidth;
// console.log(app.getBoundingClientRect());
cv.height = screenheight;
//rect.height
let canvas = new canvasSign(cv);
let dataJson;
canvas.on('drawend', (e) => {
dataJson = canvas.toJson().dataJson;
})
function upload() {
let img = document.createElement("a");
img.href = canvas.getPNGImage();
img.download = "canvas-sign.png";
img.style.display = "none";
document.body.appendChild(img);
img.click();
const formData = new FormData(canvas.getPNGImage());
//formData.append(img, img, "canvas-sign.png");
document.body.removeChild(img);
}
function colorChange(e) {
let value = e.target.options[e.target.selectedIndex].value
canvas.setLineStyle({
strokeStyle: value,
shadowColor: value
})
}
</script>
Here is Google app script's code
function doPost(e){
//var postName = e.parameter.name;
var postImg = e.parameter.img;
var folder = DriveApp.getFolderById("1yECMj1EvBQhV1gigslYJu5KM3bxsK9yy");
var copyImg = postImg.makeCopy("簽名檔", folder);
}