gwtquery icon indicating copy to clipboard operation
gwtquery copied to clipboard

FileUpload not working in Android native Browser (webkit 534.30)

Open confile opened this issue 10 years ago • 5 comments

Uploading files on Android native browser is not working with GQuery.

I tried this:

    // Use gQuery utils to create a FormData object instead
    // of JSNI
    JavaScriptObject form = JsUtils.runJavascriptFunction(window, "eval",
        "new FormData()");

    JsUtils.runJavascriptFunction(form, "append", "image", file);

    // Use gQuery ajax instead of RequestBuilder because it
    // supports FormData and progress
    Ajax.ajax(Ajax.createSettings().setUrl(url).setData((Properties) form))
    // gQuery ajax returns a promise, making the code more
    // declarative
        .progress(new Function() {
            public void f() {
            double total = arguments(0);
            double done = arguments(1);
            double percent = arguments(2);
            // Here you can update your progress bar
            GWT.log("Uploaded " + done + "/" + total + " ("
                + percent + "%)");
            }
        }).done(new Function() {
            public void f() {
            GWT.log("Files uploaded, server response is: "
                + arguments(0));
            }
        }).fail(new Function() {
            public void f() {
            GWT.log("Something went wrong: " + arguments(0));
            }
        });

confile avatar Jun 19 '14 18:06 confile

Which version of android? is the app embedded in a cordova container?

manolo avatar Jun 19 '14 18:06 manolo

Android 4.1, no the app is pure html

confile avatar Jun 19 '14 18:06 confile

it works in the Chrome browser but not in the native Browser which has a lower webkit version.

confile avatar Jun 19 '14 18:06 confile

@manolo Here is a posible solution: http://ghinda.net/jpeg-blob-ajax-android/

confile avatar Jun 19 '14 22:06 confile

It seems a different solution since their problem is to send a Blob instead of a FormData in our case. Anyway this is not a gQuery problem but a chrome bug. I leave this opened so as you can go with a solution using an ArrayBuffer instead of using a FormData. I think converting the file content into an arraybuffer, you could send using gQuery.ajax. If you dont get a solution I'll try to spend sometime when I have a while.

manolo avatar Jun 20 '14 05:06 manolo