Как загрузить изображение из интерфейса html в Google Drive с помощью скрипта Google Apps - PullRequest
0 голосов
/ 04 мая 2020

Кто-нибудь может мне помочь?

    //-------------- Camera.html------------------------------
    //HTML Code 
    //---This part is for the display

    <div style='display:inline-block'> 
    <video id="sourcevid" width='400' autoplay="true"></video>
    <div id="message" style='height:20px;width:350px;margin:5px;'>message </div> 
    <canvas id="cvs" style='display:inline-block'></canvas> 
    <button onclick='Open_Webcam()' >Open the camera</button>
    <button onclick='Get_photo()' >Take photo</button> 
    <button onclick='getHtmlImage()' >HTMLtoDRIVE</button>
</div>
<script>
//---This function is used to run the  google script <br/> <br/>
 function getHtmlImage() { <br/>
       var TheBlob = new Blob(document.getElementById('cvs'));<br/>
       google.script.run.SendToDrive(TheBlob);<br/>
      }<br/>
     <br/>
//---This function open the webcam <br/> <br/>
    function Open_Webcam() {<br/>
    navigator.mediaDevices.getUserMedia({ audio: false, video: { width: 400 } }).then(function(mediaStream) { <br/>
      var video = document.getElementById('sourcevid');<br/>
      video.srcObject = mediaStream;<br/>

      var tracks = mediaStream.getTracks();<br/>

      document.getElementById("message").innerHTML="message: "+tracks[0].label+" connecté" <br/>

      console.log(tracks[0].label)<br/>
      console.log(mediaStream) <br/>

      video.onloadedmetadata = function(e) {<br/>
       video.play(); <br/>
      };<br/>

     }).catch(function(err) { console.log(err.name + ": " + err.message);<br/>

     document.getElementById("message").innerHTML="message: connection refusé"});<br/>
    }<br/>
<br/>

//---This function capture the photo <br/> <br/>
    function Get_photo(){<br/>

     var vivi = document.getElementById('sourcevid');<br/>
     var canvas1 = document.getElementById('cvs')
     var ctx =canvas1.getContext('2d');
     canvas1.height=vivi.videoHeight
     canvas1.width=vivi.videoWidth
     console.log(vivi.videoWidth)
     ctx.drawImage(vivi, 0,0, vivi.videoWidth, vivi.videoHeight);<br/>
    } <br/>
    </script>
//------End-------- Camera.html------------------------------

    //--------------Code.gs --------------------------------
    //This fuction send the photo to drive

    function SendToDrive(object) {
       var thisfile = SpreadsheetApp.getActiveSpreadsheet().getId();
       var driveid = DriveApp.getFileById(thisfile).getParents().next().getId();
       var folder = DriveApp.getFolderById(driveid);
       var newBlob = Utilities.newBlob(object, MimeType.JPEG, "Test");
       var file = folder.createFile(newBlob);
       return file.getId();
    }
//myFunction is the start function from de script editor <br/><br/>
function myFunction() {<br/>
  var template = HtmlService.createTemplateFromFile("Camera.html");<br/>
  var html = template.evaluate();<br/>
  html.setTitle("Display");<br/>
  SpreadsheetApp.getUi().showSidebar(html); 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...