Estou tentando através do Google Script criar um formulário em que haja alguns botões para upload de arquivos em que eles irão direto para o Google Drive. Estou usando um código que obtive na internet, porém preciso adicionar mais botões para anexar arquivos. Consegui, mas só vai um arquivo para o Google Drive.
Segue o código do arquivo "forms.html":
<!DOCTYPE html><html><head><basetarget="_blank"><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>Google File Upload by CTRLQ.org</title><linkhref="https://fonts.googleapis.com/icon?family=Material+Icons"rel="stylesheet"><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/css/materialize.min.css"><style>.disclaimer{width:480px; color:#646464;margin:20pxauto;padding:016px;text-align:center;font:40012pxRoboto,Helvetica,Arial,sans-serif}.disclaimer a{color:#009688}#credit{display:none}</style></head><body><!-- Written by Amit Agarwal amit@labnol.org --><formclass="main"id="form"novalidate="novalidate"style="max-width:480px;margin:40pxauto;"><divid="forminner"><divclass="row"><divclass="col s12"><h5class="center-align teal-text">Upload Files to my Google Drive</h5><pclass="disclaimer">This <ahref="http://www.labnol.org/internet/file-upload-google-forms/29170/">File Upload Form</a> (<ahref="https://youtu.be/C_YBBupebvE">tutorial</a>) is powered by <ahref="https://ctrlq.org/code/19747-google-forms-upload-files"target="_blank">Google Scripts</a></p></div></div><divclass="row"><divclass="input-field col s12"><inputid="name"type="text"name="Name"class="validate"required=""aria-required="true"><labelfor="name">Name</label></div></div><divclass="row"><divclass="input-field col s12"><inputid="email"type="email"name="Email"class="validate"required=""aria-required="true"><labelfor="email">Email Address</label></div></div><divclass="row"><divclass="file-field input-field col s12"><divclass="btn"><span>File</span><inputid="files"type="file"></div><divclass="file-path-wrapper"><inputclass="file-path validate"type="text"placeholder="Select a file on your computer"></div></div></div><divclass="row"><divclass="file-field input-field col s12"><divclass="btn"><span>File2</span><inputid="files2"type="file"></div><divclass="file-path-wrapper"><inputclass="file-path validate"type="text"placeholder="Select a file on your computer"></div></div></div><divclass="row"><divclass="input-field col s6"><buttonclass="waves-effect waves-light btn submit-btn"type="submit"onclick="submitForm();returnfalse;">Submit</button></div></div><divclass="row"><divclass="input-field col s12"id="progress"></div></div></div><divid="success"style="display:none"><h5class="left-align teal-text">File Uploaded</h5><p>Your file has been successfully uploaded.</p><p>The <ahref="http://www.labnol.org/internet/file-upload-google-forms/29170/">pro version</a> (see <ahref="http://j.mp/GoogleFormsDemo">demo form</a>) includes a visual drag-n-drop form builder, CAPTCHAs, the form responses are saved in a Google Spreadsheet and respondents can upload multiple files of any size.</p><pclass="center-align"><aclass="btn btn-large"href="https://gum.co/GA14?wanted=true"target="_blank">Upgrade to Pro</a></p></div></form><divclass="fixed-action-btn horizontal"style="bottom:45px; right:24px;"><aclass="btn-floating btn-large red"><iclass="large material-icons">menu</i></a><ul><li><aclass="btn-floating red"href="https://gum.co/GA14"target="_blank"title="Buy License - File Upload Form"><iclass="material-icons">monetization_on</i></a></li><li><aclass="btn-floating blue"href="https://youtu.be/C_YBBupebvE"target="_blank"title="Video Tutorial"><iclass="material-icons">video_library</i></a></li><li><aclass="btn-floating green"href="http://www.labnol.org/internet/file-upload-google-forms/29170/"target="_blank"title="How to Create File Upload Forms"><iclass="material-icons">help</i></a></li></ul></div><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/js/materialize.min.js"></script><scriptsrc="https://gumroad.com/js/gumroad.js"></script><script>var file,
reader =newFileReader();
reader.onloadend =function(e){if(e.target.error !=null){
showError("File "+ file.name +" could not be read.");return;}else{
google.script.run
.withSuccessHandler(showSuccess).uploadFileToGoogleDrive(e.target.result, file.name, $('input#name').val(), $('input#email').val());}};function showSuccess(e){if(e ==="OK"){
$('#forminner').hide();
$('#success').show();}else{
showError(e);}}function submitForm(){var files = $('#files')[0].files;if(files.length ===0){
showError("Please select a file to upload");return;}
file = files[0];if(file.size >1024*1024*5){
showError("The file size should be < 5 MB. Please <a href='http://www.labnol.org/internet/file-upload-google-forms/29170/' target='_blank'>upgrade to premium</a> for receiving larger files in Google Drive");return;}
showMessage("Uploading file..");
reader.readAsDataURL(file);}function showError(e){
$('#progress').addClass('red-text').html(e);}function showMessage(e){
$('#progress').removeClass('red-text').html(e);}</script></body></html>
Pergunta
crhistianosa
Estou tentando através do Google Script criar um formulário em que haja alguns botões para upload de arquivos em que eles irão direto para o Google Drive. Estou usando um código que obtive na internet, porém preciso adicionar mais botões para anexar arquivos. Consegui, mas só vai um arquivo para o Google Drive.
Segue o código do arquivo "forms.html":
Abaixo o código "Server.gs":
/* RECEIVE FILES IN GOOGLE DRIVE - - - - - - - - - - - - - - - Tutorial: www.labnol.org/awesome Twitter: @labnol Email: amit@labnol.org */ function doGet(e) { return HtmlService.createHtmlOutputFromFile('forms.html').setTitle("Google File Upload by CTRLQ.org"); } function uploadFileToGoogleDrive(data, file, name, email) { try { var dropbox = "Received Files"; var folder, folders = DriveApp.getFoldersByName(dropbox); if (folders.hasNext()) { folder = folders.next(); } else { folder = DriveApp.createFolder(dropbox); } /* Credit: www.labnol.org/awesome */ var contentType = data.substring(5,data.indexOf(';')), bytes = Utilities.base64Decode(data.substr(data.indexOf('base64,')+7)), blob = Utilities.newBlob(bytes, contentType, file), file = folder.createFolder([name, email].join(" ")).createFile(blob); return "OK"; } catch (f) { return f.toString(); } }
Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.