ArcBees / gwtquery

A jQuery clone for GWT, and much more.
MIT License
85 stars 38 forks source link

FileUpload not working in Android native Browser (webkit 534.30) #294

Open confile opened 10 years ago

confile commented 10 years ago

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));
            }
        });
manolo commented 10 years ago

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

confile commented 10 years ago

Android 4.1, no the app is pure html

confile commented 10 years ago

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

confile commented 10 years ago

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

manolo commented 10 years ago

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.