Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    uploadItem.addChangedHandler does not fire twice with same file name

    Hi,

    I have a problem with addChangedHandler(...) method on UploadItem.

    Code:
    uploadItem.addChangedHandler(new ChangedHandler() {
    
                @Override
                public void onChanged(ChangedEvent event) {
                    // doSomething
                    doSomething();
                }
            });
    My 1st scenario :

    - Click on UploadItem then choose file "image.jpg"
    - The onChanged(...) method is executed
    - Click again on UploadItem then choose same file "image.jpg"
    - The onChanged(...) method is NOT executed

    My 2nd scenario :

    In two different directories I have two images with same file name but different binary data

    - filePath1/image.jpg -> the picture of a dog
    - filePath2/image.jpg -> the picture of a cat

    - Click on UploadItem then choose file "image.jpg" (dog image)
    - The onChanged(...) method is executed
    - Click again on UploadItem then choose "image.jpg" (cat image)
    - The onChanged(...) method is NOT executed

    I did the same with multiple files chosen in the file chooser, results are the same if file(s) name(s) are the same no matter on binary content.

    It seems FormItem's detect value has been changed only looking on file name which is problematic for me.
    I would like it systematic even if same file (same binary content) is beeing chosen several times.

    Isomorphic, can you confirm me please that this is a bug ?

    GWT Version : 2.6.1
    SmartGWT Version : 5.0-p20141210
    Firefox version : 24

    I did the test with Firefox 36 also and the results are the same.

    Thanks by advance.

    #2
    The browser does not in general tell us complete information about the file, including the full path, so the change() handler is not reliable. There is no way around this, as it's a security issue.

    Comment


      #3
      I've found a workaround to make fire several times changed handler with same file name, each time tou have to perform :

      Code:
      uploadItem.clearValue();

      Comment


        #4
        That will indeed make it fire every time, if that's what you wanted, but you should carefully test whether that actually works on all the browsers you need to support.

        Reliably telling whether the chosen file is different is not possible cross-browser.

        Comment


          #5
          Thanks for advice.

          Firefox 24 is my client target browser/version and the reset values method works on it.

          If one day my client change version of Firefox, we would add a big ugly "UPLOAD" button.

          Comment


            #6
            Actually on new browsers it's possible to know more information about selected file, you can get a full file content too. Maybe it will help for implementing change detection

            File.lastModifiedDate
            File.size

            https://developer.mozilla.org/en/docs/Web/API/FileList
            https://developer.mozilla.org/en-US/docs/Web/API/File

            Btw new browsers has XMLHttpRequest2 which allows multipart ajax post with attached files, there is example http://www.html5rocks.com/en/tutorials/file/xhr2/
            e.g. it could be used to upload files from DynamicForm without using hidden iframe on compatible browsers.

            Why would you have not incorporated any of these new browser features in your SmartClient's core?

            Comment


              #7
              We already use these features, for example, in modern browsers we implement file size validation in the browser without ever sending the file to the server.

              However if we implemented change detection when such features aren't available on all browsers, that would just lead to customers having code that appears to work in whatever browser they test, but not others - avoiding this is the whole point of having a framework.

              Also by the way, we're not sure what the point of detecting this change is in your application. If you can articulate a purpose for being able to detect the change, it might help prioritize adding the feature in the future, when cross-browser support is possible.

              Comment

              Working...
              X