6 Replies Latest reply on Nov 26, 2014 8:58 AM by michpetrov

    JS API for RichFaces fileUpload

    michal_d

      Hello,

       

      I would like to know whether info from this table:

       

      RichFaces Migration Guide. 3.3.x - 4.x Migration - Components migration - Rich Input Components

       

      is still current? In particular, is there any chance to access uploaded files in fileUpload object from JavaScript?

       

      And if JS API is really not implemented yet. Will it be implemented in the future?

       

      Regards and thanks

        • 1. Re: JS API for RichFaces fileUpload
          michpetrov

          Hi,

           

          the component is backed by a JS object so an API is there but I don't think there are methods specifically to let you control the component. As for the question - you can access files that have been selected by the user (or their JS representation) but you cannot access the files that have been put on the server if that's what you mean.

          1 of 1 people found this helpful
          • 2. Re: JS API for RichFaces fileUpload
            michal_d

            Hi,

             

            thank you for your answer. I'm not entirely sure that I understood you correctly so maybe I will just write more specifically what I need to do.

             

            I have a rich:fileUpload component with immediateUpload set to true and maxFilesQuantity = 1 so basically after user chooses file he wants to upload the upload is happening and the listener method is invoked. Now I need to add some JavaScript event handler in which I would be able to access this uploaded file (not to change anything, just retrieve some info about the file). Before or after the listener method, it doesn't matter. Is it possible?

            • 3. Re: JS API for RichFaces fileUpload
              michpetrov

              Ah ok, that's not possible. The purpose of the component is to transfer files to the server, it doesn't care what happens with those files after they're delivered. You can ask the server about the files with an AJAX request, but you'd have to implement that yourself. Or you can process the file in a bean and then output the information, like we do in the showcase.

              1 of 1 people found this helpful
              • 4. Re: JS API for RichFaces fileUpload
                michal_d

                Ok, thank you for your answers.

                • 5. Re: JS API for RichFaces fileUpload
                  michal_d

                  Hi,

                   

                  I would like to ask one more question about rich:fileupload. This use case which I described above concerns an image uploader. I need to process uploaded image in my bean but I need to display it to the user as well (before saving in database). In your showcase you use session scoped bean to achieve that. I don't want to use session scoped bean and with view scoped bean I can't use mediaoutput component. I managed to do a workaround in JavaScript but I need to access this uploaded image and you said it's impossible.

                   

                  My question is: do you have idea how to solve this problem? Or maybe, could you be more specific about asking server about that file with an AJAX request? Any example?

                  • 6. Re: JS API for RichFaces fileUpload
                    michpetrov

                    If the file isn't saved anywhere and just exists in the memory I don't think you can get to it with JavaScript at all. If it was saved you'd have at least an URL to work with.