When will get Multiple-File-Input(<input type="file" multiple="" />) supported?

479 views
Skip to first unread message

Alex Luya

unread,
Jun 13, 2011, 2:41:11 AM6/13/11
to google-we...@googlegroups.com
I think this is a urgent needs for many scenarios,but don't get
supported right now.Many other solutions available,but a pure gwt way is
better.When will we get this supported officially?

Thomas Broyer

unread,
Jun 13, 2011, 11:48:30 AM6/13/11
to google-we...@googlegroups.com
The issue is: what behavior do you expect on browsers that do not support this feature?

In the mean time: fileUpload.getElement().setPropertyBoolean("multiple", true");

Jeff Larsen

unread,
Jun 13, 2011, 12:49:22 PM6/13/11
to google-we...@googlegroups.com
There already exists a pattern for something like that. @PartialSupport etc. the static  #createIfSupported() method on the classes. I suppose adding a createMultipleIfSupported. I would venture a guess, adding multiple=true to the param would just be ignored on browsers that don't support it (I have not tested this theory however).

Jim Douglas

unread,
Jun 13, 2011, 1:24:37 PM6/13/11
to Google Web Toolkit
I added this to my ClientFileChooser -- just pass in the option and
hope for the best.

public void setMultipleSelect(boolean p_multipleSelect)
{
DOM.setElementPropertyBoolean(m_fileUpload.getElement(),
"multiple",
p_multipleSelect);

Alex Luya

unread,
Jun 15, 2011, 11:58:37 AM6/15/11
to google-we...@googlegroups.com
Actually,same thing can be done in uibinder's xml file,but question is
how to get selected file list:
-------------------------------------------------------------------------
private VerticalPanel vPanel;

public void onModuleLoad()
{
VerticalPanel wrapper = new VerticalPanel();
final FileUpload uploader = new FileUpload();
uploader.getElement().setPropertyBoolean("multiple", true);
wrapper.add(uploader);
wrapper.add(vPanel = new VerticalPanel());
uploader.addChangeHandler(new ChangeHandler()
{

@Override
public void onChange(ChangeEvent event)
{
String fileName = uploader.getFilename();
for (String file : fileName.split(","))
{
vPanel.add(new Label(file));
}

}
});

RootPanel.get().add(wrapper);
}
-----------------------------------------------------------------------------------
selected files will be list in file name box(you can see them if using
firefox),but FileUpload.getFileName() will get only first file name,and
further work is how to handle uploading?

> --
> You received this message because you are subscribed to the Google
> Groups "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/wV6toVIq388J.
> To post to this group, send email to
> google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-toolkit
> +unsub...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.

Thomas Broyer

unread,
Jun 15, 2011, 12:13:14 PM6/15/11
to google-we...@googlegroups.com
JSNI and JavaScriptObject "overlay types" FTW!

Alex Luya

unread,
Jun 21, 2011, 3:11:28 AM6/21/11
to google-we...@googlegroups.com
How to get file list? can you post a code split to show how to do it?
----------------------------------------------------------------------
public static native void getFiles() /*-{
var input =this.@com.domain.client.Clx::fileUpload;

for (var i = 0; i < input.files.length; i++) {
$wnd.alert(input.files[i].name);
}
return
}-*/;
--------------------------------------------------------------------------
Above code will report error:
--------------------------------------------------------------------------
Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError):
Cannot read property 'files' of undefined
--------------------------------------------------------------------------

On Wed, 2011-06-15 at 09:13 -0700, Thomas Broyer wrote:
> JSNI and JavaScriptObject "overlay types" FTW!
>

> --
> You received this message because you are subscribed to the Google
> Groups "Google Web Toolkit" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/google-web-toolkit/-/lNk39MwjwWgJ.

Thomas Broyer

unread,
Jun 21, 2011, 5:12:08 AM6/21/11
to google-we...@googlegroups.com


On Tuesday, June 21, 2011 9:11:28 AM UTC+2, Alex Luya wrote:
How to get file list? can you post a code split to show how to do it?
----------------------------------------------------------------------
public static native void getFiles() /*-{
var input =this.@com.domain.client.Clx::fileUpload;

'static' + 'this' ?!
 
       
       for (var i = 0; i < input.files.length; i++) {
          $wnd.alert(input.files[i].name);
       }
return
}-*/;

Yes, that's the idea (we made a JavaScriptObject for the File JS object, and a helper method to get a JsErray<JsFile> out of an InputElement)
 
--------------------------------------------------------------------------
Above code will report error:
--------------------------------------------------------------------------
Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError):
Cannot read property 'files' of undefined  
--------------------------------------------------------------------------



Also, is your fileUpload field an InputElement or a FileUplaod widget? if a FileUpload widget, you'll have to call @.com.google.gwt.user.client.ui.Widget::getElement() on it first.
Reply all
Reply to author
Forward
0 new messages