Skip to content
Browse files

add some fileuploadform method

  • Loading branch information...
1 parent 8d6946a commit 85ddce17822146b0990f8e265c374dff32a6d478 aki committed
View
3 src/com/akjava/gwt/html5/client/file/FileUploadForm.java
@@ -18,4 +18,7 @@ public FileUploadForm(){
fileUpload = new FileUpload();
add(fileUpload);
}
+
+
+
}
View
35 src/com/akjava/gwt/html5/client/file/FileUtils.java
@@ -17,6 +17,8 @@
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.NativeEvent;
+import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.Element;
public class FileUtils {
@@ -43,6 +45,39 @@ public static final native void addDropListener(Element element,DropListener lis
},false);
}-*/;
+ //TODO support other case
+ /*
+ * why need reset because sometime you would like to re-upload modified same file.in such case it need reset though it's use change-handler.
+ */
+ public static FileUploadForm createSingleFileUploadForm(final DataURLListener listener,final boolean reset){
+ final FileUploadForm form=new FileUploadForm();
+ form.getFileUpload().addChangeHandler(new ChangeHandler() {
+ @Override
+ public void onChange(ChangeEvent event) {
+ final FileReader reader=FileReader.createFileReader();
+ final JsArray<File> files=FileUtils.toFile(event.getNativeEvent());
+ if(files.length()>0){
+ reader.setOnLoad(new FileHandler() {
+ @Override
+ public void onLoad() {
+ listener.uploaded(files.get(0), reader.getResultAsString());
+ if(reset){
+ form.reset();
+ }
+ }
+ });
+ reader.readAsDataURL(files.get(0));
+ }
+
+ }
+ });
+ return form;
+ }
+
+ public interface DataURLListener{
+ public void uploaded(File file,String value);
+ }
+
}

0 comments on commit 85ddce1

Please sign in to comment.
Something went wrong with that request. Please try again.