6 Replies Latest reply on Jul 8, 2010 4:57 AM by weijie chi

    About upload a 0 size .txt file with ie7 or ie8

    weijie chi Newbie

      In my web project,I can upload .txt file larger than 0 successfully,however  when I'm attempting to upload a 0 size .txt file,I get the message  "Transfer error occurred" on the brower,it seems that there is nothing upload. I have tried to debug the error,all the listener like onuploadcomplete,ontyperejected and fileUploadListener were not triggered.And It works good on firefox brower.

      The codes are  as following:

       

      <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
                             maxFilesQuantity="1"
                             id="uploadFile"
                             required="true"
                             allowFlash="auto"
                             acceptedTypes="txt,csv,xls,xlsx"
                             listWidth="344px" listHeight="40px" immediateUpload="true"
                             addControlLabel="Browse..."
                             disabled="#{empty createList.listName}">

       

                    <a4j:support event="onuploadcomplete" immediate="true" reRender="info,textEmptyWarn,updateStatusBottom,updateStatusTop" actionListener="#{createList.setSuccessUpload}" />
                    <a4j:support event="ontyperejected" immediate="true" actionListener="#{fileUploadBean.setFailureUpload}" />

       

                  </rich:fileUpload>

       

      Can anyone give me an idea?

        • 1. Re: About upload a 0 size .txt file with ie7 or ie8
          Nick Belaevski Master

          Hi,

           

          Thank you for reporting the problem! I've created https://jira.jboss.org/browse/RF-8891 for this. The problem seems to be affecting only Flash-enabled mode of rich:fileUpload, so you can try switching it off.

          • 2. Re: About upload a 0 size .txt file with ie7 or ie8
            weijie chi Newbie

            Thank you for your reply,however I can't turn off  the Flash mode since it will object my product request.

            • 3. Re: About upload a 0 size .txt file with ie7 or ie8
              Pavel Yaschenko Newbie

              It's a hack but you can try to redefine fileupload js function and insert verification.

               

              something like this:

               

              var backup_flashAdd = FileUpload.prototype._flashAdd;
              FileUpload.prototype._flashAdd = function (files) {

                   // delete files from array with size==0

                   // see original code below

                   // call original function

                  backup_flashAdd.call(this, files);

              }

               

              or like this (original code + verification + comments):

               

              Object.extend(FileUpload.prototype, {
                   _flashAdd: function(files) {
                   if (this.disabled) return;
                   var filesArray = [];
                   for (var i=this.entries.length; i<files.length;i++)
                   {
                        var file = files[i];
                        if (file.size!=0) {// file size verification here
                             this.currentInput.value = files[i].name;
                             this.createFrame();
                             var newEntry = new FileUploadEntry(this.currentInput, this, file.size, file.type, file.creator, file.creationDate, file.modificationDate);
                             this.entries.push(newEntry);
                             filesArray.push(newEntry);
                             if (this.runUpload) {
                                  newEntry.setState(FileUploadEntry.READY);
                             } else {
                                  newEntry.setState(FileUploadEntry.INITIALIZED);
                             }
                             var newUpload = this.currentInput.cloneNode(true);
                             this.currentInput.style.cssText = "position: absolute; right: 0px; top: 0px; display: none; visibility: hidden;";
                             newUpload.id = this.id + ":file" + (this.idCounter++);
                             newUpload.value = '';
                             this.currentInput.parentNode.appendChild(newUpload);
                             this.currentInput = newUpload;
                        } else { // end size verification
                        // put some alert here if needed
                        }      }      if (this.events.onadd) {           this.element.fire("rich:onadd", { entries : filesArray });      }      if (this.runUpload) {           this.upload();      }      } });
              • 4. Re: About upload a 0 size .txt file with ie7 or ie8
                weijie chi Newbie

                Hi Nick,

                    Can you tell me when will the the Rich Faces Jira will be resolve,or an approximate time.

                 

                                                                                                                                            Thanks!

                • 5. Re: About upload a 0 size .txt file with ie7 or ie8
                  Nick Belaevski Master

                  Currently we are not planning 3.x releases. Please use workaround posted by Pavel.

                  • 6. Re: About upload a 0 size .txt file with ie7 or ie8
                    weijie chi Newbie

                    Thanks´╝îI will have try!