Google Apps Script

Class FileUpload

A widget that wraps the HTML <input type='file'> element. This widget must be used within a FormPanel.

The result of a FileUpload is a "Blob" which can we used in various other functions. Below is an example of how to use FileUpload.

 
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());
   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;
   var doc = DocsList.createFile(fileBlob);
 }
 

Internally, UiApp widgets are built on top of the Google Web Toolkit, and it can sometimes be helpful to look at the GWT documentation directly. You can find the FileUpload documentation here.

Methods

MethodReturn typeBrief description
addChangeHandler(handler)FileUploadAdd a handler for change events.
addStyleDependentName(styleName)FileUploadSets the dependent style name of this FileUpload.
addStyleName(styleName)FileUploadAdds a style name to this FileUpload.
getId()StringReturns the id that has been assigned to this object.
getTag()StringGets the text tag of this FileUpload.
getType()StringGets the type of this object.
setEnabled(enabled)FileUploadSets whether the FileUpload is enabled.
setHeight(height)FileUploadSets the height of this FileUpload.
setId(id)FileUploadSets the id of this FileUpload.
setName(name)FileUploadSets the name of the FileUpload, which is how it will be referred to when used in a FormPanel or as a callback element on an event handler.
setPixelSize(width, height)FileUploadSets the size of this FileUpload in pixels.
setSize(width, height)FileUploadSets the size of this FileUpload.
setStyleAttribute(attribute, value)FileUploadSets one of this FileUpload's style attributes to a new value.
setStyleAttributes(attributes)FileUploadSets this FileUpload's style attributes.
setStyleName(styleName)FileUploadSets the style name of this FileUpload.
setStylePrimaryName(styleName)FileUploadSets the primary style name of this FileUpload.
setTag(tag)FileUploadSets the text tag of this FileUpload.
setTitle(title)FileUploadSets the hover title of this FileUpload.
setVisible(visible)FileUploadSets whether this FileUpload is visible.
setWidth(width)FileUploadSets the width of this FileUpload.

Detailed documentation

addChangeHandler(handler)

Add a handler for change events.

Note that you can have multiple handlers for the same event on the same widget. They will be called in the order that they were added to the widget, although ServerHandlers may appear to happen simultaneously.

The handler passes back some information to the server about what happened. This information can be accessed as follows:

 
function doGet() {
   var app = UiApp.createApplication();
   var textBox = app.createTextBox();
   var handler = app.createServerHandler("handlerFunction");
   textBox.addChangeHandler(handler);
   app.add(textBox);
   return app;
 }

 function handlerFunction(eventInfo) {
   var parameter = eventInfo.parameter;
   // the type of event, in this case "change".
   var eventType = parameter.eventType;
   // the id of the widget that fired this event.
   var source = parameter.source;
 }
 
In addition, the values of certain widgets can be sent up with the event as well, as "callback elements." See the documentation of ServerHandler for more information.

Parameters

NameTypeDescription
handlerHandlerthe handler to execute when the event occurs. This can be a ClientHandler or a ServerHandler.

Return

FileUpload — the FileUpload itself, useful for chaining.


addStyleDependentName(styleName)

Sets the dependent style name of this FileUpload.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

FileUpload — the FileUpload itself, useful for chaining.


addStyleName(styleName)

Adds a style name to this FileUpload.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

FileUpload — the FileUpload itself, useful for chaining.


getId()

Returns the id that has been assigned to this object.

This can be used in conjunction with app.getElementById() to retrieve a reference to this object.

Return

String — the id that has been assigned to this object


getTag()

Gets the text tag of this FileUpload.

Return

String — the text tag.


getType()

Gets the type of this object.

Return

String — the object type


setEnabled(enabled)

Sets whether the FileUpload is enabled.

Parameters

NameTypeDescription
enabledBooleanwhether the FileUpload should be enabled or disabled.

Return

FileUpload — the FileUpload itself, useful for chaining.


setHeight(height)

Sets the height of this FileUpload.

Parameters

NameTypeDescription
heightStringthe new height in any CSS unit such as "10px" or "50%".

Return

FileUpload — the FileUpload itself, useful for chaining.


setId(id)

Sets the id of this FileUpload.

Parameters

NameTypeDescription
idStringthe new id, which can be used to retrieve the FileUpload from app.getElementById(id).

Return

FileUpload — the FileUpload itself, useful for chaining.


setName(name)

Sets the name of the FileUpload, which is how it will be referred to when used in a FormPanel or as a callback element on an event handler.

Parameters

NameTypeDescription
nameStringthe new name.

Return

FileUpload — the FileUpload itself, useful for chaining.


setPixelSize(width, height)

Sets the size of this FileUpload in pixels.

Parameters

NameTypeDescription
widthIntegerthe new width in pixels.
heightIntegerthe new height in pixels.

Return

FileUpload — the FileUpload itself, useful for chaining.


setSize(width, height)

Sets the size of this FileUpload.

Parameters

NameTypeDescription
widthStringthe new width in any CSS unit such as "10px" or "50%".
heightStringthe new height in any CSS unit such as "10px" or "50%".

Return

FileUpload — the FileUpload itself, useful for chaining.


setStyleAttribute(attribute, value)

Sets one of this FileUpload's style attributes to a new value. Valid attributes are listed here; the values for each attribute are the same as those available in CSS style sheets.

 
// Change the widget's background to black and text color to green.
 widget.setStyleAttribute("background", "black")
     .setStyleAttribute("color", "green");
 

Parameters

NameTypeDescription
attributeStringthe CSS attribute, in camel-case ("fontSize", not "font-size"), as listed here
valueStringthe CSS value

Return

FileUpload — the FileUpload itself, useful for chaining.


setStyleAttributes(attributes)

Sets this FileUpload's style attributes. This is a convenience method that is equivalent to calling setStyleAttribute with every key/value pair in the attributes object. Valid attributes are listed here; the values for each attribute are the same as those available in CSS style sheets.

 
// Change the widget's background to black and text color to green.
 widget.setStyleAttributes({background: "black", color: "green"});
 

Parameters

NameTypeDescription
attributesObjectan object of key/value pairs for the CSS attributes and values to set; valid attributes are listed here

Return

FileUpload — the FileUpload itself, useful for chaining.


setStyleName(styleName)

Sets the style name of this FileUpload.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

FileUpload — the FileUpload itself, useful for chaining.


setStylePrimaryName(styleName)

Sets the primary style name of this FileUpload.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

FileUpload — the FileUpload itself, useful for chaining.


setTag(tag)

Sets the text tag of this FileUpload.

Parameters

NameTypeDescription
tagStringthe new text tag, which can be anything you wish to store with the widget.

Return

FileUpload — the FileUpload itself, useful for chaining.


setTitle(title)

Sets the hover title of this FileUpload.

Not all browsers will show this.

Parameters

NameTypeDescription
titleStringthe hover title.

Return

FileUpload — the FileUpload itself, useful for chaining.


setVisible(visible)

Sets whether this FileUpload is visible.

Parameters

NameTypeDescription
visibleBooleanwhether this FileUpload should be visible or not.

Return

FileUpload — the FileUpload itself, useful for chaining.


setWidth(width)

Sets the width of this FileUpload.

Parameters

NameTypeDescription
widthStringthe new width in any CSS unit such as "10px" or "50%".

Return

FileUpload — the FileUpload itself, useful for chaining.

Deprecated methods

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.