19 Replies Latest reply on Jun 28, 2012 6:20 AM by Ryan Rutan

    Upload files from a plugin

      Does anyone knows if an upload component already exists or I have to write my own (if feasible)?  I developed a plugin that lives in the admin site and one of the form needs a file upload.  After the file is uploaded I need to use it in my application.


      Thoughts, suggestion?


      Thank you!

        • Re: Upload files from a plugin

          Hi Geoff,


          I have used JiveMultiPartRequest, which is defined in struts.properties as


          ### Parser to handle HTTP POST requests, encoded using the MIME-type multipart/form-data


          I'm pretty sure if the mime type of the HTTP POST is multipart/form then it is runs.  In the action class you

          need to define some setters like these


          public void setUpload(File file) {
                 this.file = file;
          public void setFilename(String filename) {
            this.filename = filename;
          public String getFilename() {
            return filename;
          public void setUploadContentType(String contentType) {
                 this.contentType = contentType;
            • Re: Upload files from a plugin

              Thank you very much, I'll take a look today!

              • Re: Upload files from a plugin

                I am probably not too far from a solution.  Currently the 3 variables are null when I execute the action.


                private File upload;

                private String uploadContentType;

                private String uploadFileName;


                The form

                <form enctype="multipart/form-data" id="uploadForm" method="POST" action="action-save-create!upload.jspa">

                  <input type="file" id="upload" name="upload" />

                  <input type="submit" name="save" value="upload" />



                The Action

                <action name="action-save-create" class="com.jivesoftware.action.SaveAdminAction">

                  <result name="error" type="freemarker">/mytemplate.ftl</result>

                  <result name="input" type="freemarker">/mytemplate.ftl</result>

                  <result name="success" type="freemarker">/mytemplate.ftl</result>


                  • Re: Upload files from a plugin
                    Ryan Rutan

                    So based on your snippets, make sure that your setFilename => setUploadFileName.  Per the struts2 pattern, all 3 fields need to be prefixed with the base parameter name.  Hope that fixes it. =)

                      • Re: Upload files from a plugin

                        Hey Ryan Rutan thank you for your help!


                        Like that?


                        public void setUpload(File upload) {

                             this.upload = upload;



                        public void setUploadContentType(String uploadContentType) {

                             this.uploadContentType = uploadContentType;



                        public void setUploadFileName(String uploadFileName) {

                             this.uploadFileName = uploadFileName;


                          • Re: Upload files from a plugin
                            Ryan Rutan

                            If I were Struts2 (and I'm not saying I am), I would have to like how that is set up. =)

                            • Re: Upload files from a plugin

                              2012-06-27 11:08:09,320 [http-] [:admin] ERROR com.jivesoftware.community.action.PageViewInterceptor - Exception encountered -


                                      at com.jivesoftware.sidlee.quickwidgets.action.CarouselAdminUploadAction.execute(CarouselAdminUploadAction.java:58)

                                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                                      at java.lang.reflect.Method.invoke(Method.java:597)

                                      at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:376)

                                      at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:239)

                                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:213)

                                      at com.jivesoftware.community.action.DisableCacheInterceptor.intercept(DisableCacheInterceptor.java:36)

                                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:211)

                        • Re: Upload files from a plugin
                          Ryan Rutan

                          Were you logged in during this screenshot?  Also, can you try removing the SystemAdmin check for now..and do some output that will allow us to determine if the File Upload is working.  Perhaps addActionMessage("filename:"+getUploadFileName()); or something like that?  Not sure how this would have gotten to line 58 in previous iterations and now not making it passed the first 3 lines. =\

                            • Re: Upload files from a plugin

                              <action name="carousel-upload-image" class="com.jivesoftware.sidlee.quickwidgets.action.UploadAction">

                                     <interceptor-ref name="fileUpload">

                                       <param name="maximumSize">999999999999</param>

                                       <param name="allowedTypes">




                                   <interceptor-ref name="defaultStack"></interceptor-ref>

                                <result name="error" type="freemarker">/plugins/quickWidgets/resources/templates/admin/carousel/carousel-list.ftl</result>

                                <result name="input" type="freemarker">/plugins/quickWidgets/resources/templates/admin/carousel/carousel-list.ftl</result>

                                <result name="success" type="freemarker">/plugins/quickWidgets/resources/templates/admin/carousel/carousel-list.ftl</result>


                          • Re: Upload files from a plugin

                            Hey Ryan Rutan thank you for your help on that one, at last it works!


                            Now that I am able to upload photos, do you know how to access it from a URL?  When uploaded, the photo lives in the folder '/usr/local/jive/applications/sbs/home/images/carousel/[image].ext'.


                            Thank you! Have a nice day!

                              • Re: Upload files from a plugin
                                Ryan Rutan

                                You can try <YOUR_HOST>/resources/images/carousel/*  but honestly I would just find other images in the same folder...then view source for their names in the source code.  I haven't personally dabbled much with adding files (for access) to the file system...so unfamiliar with web mappings. =\  Hope this helps.  Glad we get it ironed out =)