I created one google-form in that google-form i want user to upload their image. so i need a upload button to put their passport size image. i have written an separate code to upload image. where i can upload image the image comes and saved in drive. there are 2 pieces. i want this to merge or combine . i want to include a upload button image in the form and the uploaded image should come and save in the form spreadsheet. thanku
function doGet(e) {
var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");
var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton('Submit'));
app.add(form);
return app;
}
function doPost(e) {
// data returned is a blob for FileUpload widget
var fileBlob = e.parameter.thefile;
var doc = DocsList.createFile(fileBlob);
var app = UiApp.getActiveApplication();
//Display a confirmation message
var label = app.createLabel('file uploaded successfully');
app.add(label);
return app;
}
It's not possible to merge this function to a Google form.
Related
Is there a way to use file upload class and mailApp to select a (pdf) file from your computer (like this tutorial shows) and stores it only temporarily (maybe using cache memory) to send it as an email attachment?
the sample you refer to needs very few modifications to do what you want... the variable you get in the doPost is a blob, the argument needed in the attachment is a blob too so it is quite straightforward to put both together.
I only added a text on the button and a confirmation message when the mail is sent.
note that the file type will depend only on the filetype of the file, nowhere we convert it to pdf but that was not the point of your question.
if you upload a jpeg (for example) it will be a jpeg in the attachment of course !
code below with test on line:
function doGet(e) {
var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");
var formContent = app.createVerticalPanel();
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton('send'));
var form = app.createFormPanel();
form.add(formContent);
app.add(form);
return app;
}
function doPost(e) {
// data returned is a blob for FileUpload widget
var fileBlob = e.parameter.thefile;
MailApp.sendEmail(Session.getActiveUser(),'test pdf attachment','see attachment',{attachments: [fileBlob]});
var app = UiApp.getActiveApplication();
return app.add(app.createLabel('mail sent'));
}
test (asking for authorization)
var spreadsheetFile = DriveApp.getFileById(sheetId);
var blob = spreadsheetFile.getAs('application/pdf');
//if daysleft =1 or 0 then send mail .
MailApp.sendEmail(emailAddress, subject, message, {
name: 'Welcome mail- Perch Arbor Golf Course.pdf',
attachments: [blob]
});
I'm looking for how to get the file name by the FileUpload just by the file selected before a submit button pushed. But it seems not allowed.
I think the following code can probably hold up the FileUpload changed.
function doGet()
{
var app = UiApp.createApplication();
var panel = app.createVerticalPanel().setId('panel');
var fileUploader = app.createFileUpload().setName('thefile');
var handler = app.createServerHandler('fileChangeHandler');
handler.addCallbackElement(panel);
fileUploader.addChangeHandler(handler);
panel.add(fileUploader);
var form = app.createFormPanel();
form.add(panel);
app.add(panel);
return app;
}
But I don't know how to grab the file name in fileChangeHandler(). For example, the following is a failed code:
function fileChangeHandler(e)
{
var app = UiApp.getActiveApplication();
Logger.log(e.parameter.thefile);
return app;
}
Thanks very much for your comments ^^
You cannot use a regular button for FileUpload, you must use a SubmitButton. See these two answers.
GAS: GUI Builder, File Upload, Submit Button
File upload at google apps script
I can't find the way to convert the documents uploaded by my google script into the native Google Docs format.
In Drive configuration options, you can set if the uploaded document will convert automatically into Google Docs format. But when i do this in my google apps sript with the DocList.createFile() method, the convertion is not maked.
This is my script
function doGet(e) {
var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");
var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton('Submit'));
app.add(form);
return app;
}
function doPost(e) {
// data returned is a blob for FileUpload widget
var fileBlob = e.parameter.thefile;
var doc = DocsList.createFile(fileBlob);
var app = UiApp.getActiveApplication();
// display a confirmation message
var label = app.createLabel('file uploaded successfully');
app.add(label);
return app;
}
I am coding a contract application in Google App Script.
It creates a GoogleDoc from a template that include an image of the seller's signature and initials.
As there are five seller, and a dozen different templates, is there a way to change the image of signature and initials?
I have no clues where to start looking for that.
thanks and have a nice day!
Eric
EDIT : I found something about InlineImage in DocumentApp... still looking
Here is a little code which appends a an image in a Google doc. Hope this will give you Idea to get going.
Similar concept I used to make a resume builder application which replaces Profile picture and a signature image
//Make a UI form to upload Image
function doGet() {
var app = UiApp.createApplication();
//Form
var form = app.createFormPanel().setEncoding('multipart/form-data').setId('form');
//Add this form to the application
app.add(form);
//Panel to hold form elements
var panel = app.createVerticalPanel();
//add this panel inside form
form.add(panel);
//Now create form elemnts
var label1 = app.createLabel('Upload Image');
var uploadControl = app.createFileUpload().setName('file').setId('file');
var submitBtn = app.createSubmitButton('Submit');
//Add all these elemnts to the panel
panel.add(label1).add(uploadControl).add(submitBtn);
//Return the application to the service URL
return app;
}
//This function is callend when the form is submitted
function doPost(e){
var fileBlob = e.parameter.file; //This is the image blob if an image is uploded
//Open the document
var doc = DocumentApp.openById('ID OF GOOGLE DOC')//change Id of the document
//get the body of document
var docBody = doc.getActiveSection();
//Append the iamge in document body
docBody.appendImage(fileBlob);
//Save and close the document
doc.saveAndClose();
}
New to GAS and am struggling with my first script. Any help will be appreciated.
The UI displays but I cannot write data in a xls file. It was working when I was using a handler, however, I had to change it to a doPost to get file upload to work.
I want to have UI that has several fields and 2 file upload options. Does anyone have sample script that I can use to get started?
My script
function doGet(e)
Create a vertical panel with a grid that has text boxes
Create a form that has a file upload box
function doPost(e) {
var doc = SpreadsheetApp.openById('0Auxvh5UNOiURdE1uc1VOVGNlTE01bjF4THRmdzFnSXc');
var lastRow = doc.getLastRow();
var cell = doc.getRange('a1').offset(lastRow, 0);
cell.setValue(e.parameter.universityname);
cell.offset(0, 1).setValue(e.parameter.eventname);to age
cell.offset(0, 2).setValue(e.parameter.city);
var fileBlob = e.parameter.thefile;
var doc = DocsList.createFile(fileBlob);
var app = UiApp.getActiveApplication();
app.close();
return app;
}