mardi 21 juin 2016

upload picture from mit app inventor to google drive

I'm trying to send a picture to my Google Drive through MIT App Inventor. So far the website will take a picture without the submit button - it will upload as soon as selected.

I saw PHP ways of doing this but I have no background in making websites and have no idea how to link the two together.

This code makes a link to upload files to my google drive

These are my app's blocks and how it sends to the link

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('form.html');
}

function uploadFiles(form) {
  try {
    var dropbox = "pics";
    var folder, folders = DriveApp.getFoldersByName(dropbox);
    if (folders.hasNext()) {
      folder = folders.next();
    } else {
      folder = DriveApp.createFolder(dropbox);
    }
    var blob = form.myFile;    
    var file = folder.createFile(blob);    
    return "File uploaded successfully " + file.getUrl();
  } catch (error) {
    return error.toString();
  }
}

<form action="drive_upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="myFile" onchange="
                    google.script.run.withSuccessHandler(fileUploaded)
                    .uploadFiles(this.parentNode);
                    return false;">           
</form>
<form id="myForm">

    <input type="file" name="myFile" onchange="
                    google.script.run.withSuccessHandler(fileUploaded)
                    .uploadFiles(this.parentNode);
                    return false;">
</form>
<div id="output"></div>
<script>
    function fileUploaded(status) {
        document.getElementById('myForm').style.display = 'none';
        document.getElementById('output').innerHTML = status;
    }
</script>
<style>
 input { display:block; margin: 20px; }
</style>

Aucun commentaire:

Enregistrer un commentaire