Hi Chan,
What is the code that you used to upload the file?
I just tested a similar scenario using the jQuery plugin [1] and could do
it without any issue. That plugin properly sends multipart header
and boundaries. I have put a sample code as well at [2] where you can try
that out.
Further, if you want to directly write the request stream into a file, then
following code can be used where the stream is piped at Java level. For
that to work, you will need to have the latest code from Jaggery master.
var file = new File('/ruchira.jpg');
file.open('w');
file.write(request.getStream());
file.close();
[1] http://blueimp.github.io/jQuery-File-Upload/
[2]
https://github.com/wso2/jaggery/blob/master/apps/sample/multipart/index.jag
On Thu, Jun 13, 2013 at 8:13 AM, Chan <[email protected]> wrote:
> Hi all,
> I am facing an error when uploading a file using an ajax call in jaggery -
>
> I am using the request.getAllFiles() method and my request is going as
> 'multipart/form-data'.
> I am getting an error from Commons upload as not having set my multipart
> boundaries -
>
> I searched over at stackoverflow and found out that this was a common
> issue and we have to set the content-type to false -
> http://stackoverflow.com/questions/13240664/how-to-set-a-boundary-on-a-multipart-form-data-request-while-using-jquery-ajax-f
>
> Now the problem is that request.getAllFiles() will only work if the
> content-type is 'multipart-form-data'.
>
>
> Below is the error -
> 2013-06-13 07:41:27,089] ERROR
> {org.jaggeryjs.hostobjects.web.RequestHostObject} - the request was
> rejected because no multipart boundary was found
> org.apache.commons.fileupload.FileUploadException: the request was
> rejected because no multipart boundary was found
> at
> org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:954)
> at
> org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
> at
> org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
> at
> org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
> at
> org.jaggeryjs.hostobjects.web.RequestHostObject.parseMultipart(RequestHostObject.java:422)
> at
> org.jaggeryjs.hostobjects.web.RequestHostObject.jsFunction_getAllFiles(RequestHostObject.java:229)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
> at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:386)
> at
> org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:85)
> at
> org.jaggeryjs.rhino.publisher.c2._c_anonymous_1(/publisher//index.jag:15)
> at org.jaggeryjs.rhino.publisher.c2.call(/publisher//index.jag)
> at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
> at
> org.jaggeryjs.rhino.publisher.modules.c4._c_anonymous_9(/publisher/modules/goose.js:89)
> at
> org.jaggeryjs.rhino.publisher.modules.c4.call(/publisher/modules/goose.js)
> at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
> at
> org.jaggeryjs.rhino.publisher.modules.c2._c_callAPI_12(/publisher/modules/absolute.js:138)
> at
> org.jaggeryjs.rhino.publisher.modules.c2.call(/publisher/modules/absolute.js)
> at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63)
> at
> org.jaggeryjs.rhino.publisher.modules.c2._c_anonymous_14(/publisher/modules/absolute.js:169)
> at
> org.jaggeryjs.rhino.publisher.modules.c2.call(/publisher/modules/absolute.js)
> at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
> at org.jaggeryjs.rhino.publisher.c2._c_script_0(/publisher//index.jag:199)
> at org.jaggeryjs.rhino.publisher.c2.call(/publisher//index.jag)
> at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
> at
> org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
> at org.jaggeryjs.rhino.publisher.c2.call(/publisher//index.jag)
> at org.jaggeryjs.rhino.publisher.c2.exec(/publisher//index.jag)
> at
> org.jaggeryjs.scriptengine.engine.RhinoEngine.execScript(RhinoEngine.java:577)
> at
> org.jaggeryjs.scriptengine.engine.RhinoEngine.exec(RhinoEngine.java:280)
> at
> org.jaggeryjs.jaggery.core.manager.WebAppManager.execute(WebAppManager.java:377)
> at
> org.jaggeryjs.jaggery.core.JaggeryServlet.doPost(JaggeryServlet.java:29)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
> at
> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
> at
> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
> at
> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
> at org.jaggeryjs.jaggery.core.JaggeryFilter.doFilter(JaggeryFilter.java:21)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
> at
> org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:177)
> at
> org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:161)
> at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
> at
> org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:57)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> at
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
> at
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
> at
> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1653)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
> [2013-06-13 07:41:27,094] ERROR
> {org.jaggeryjs.scriptengine.engine.RhinoEngine} -
> org.mozilla.javascript.WrappedException: Wrapped
> org.jaggeryjs.scriptengine.exceptions.ScriptException:
> org.apache.commons.fileupload.FileUploadException: the request was rejected
> because no multipart boundary was found (/publisher//index.jag#15)
> [2013-06-13 07:41:27,095] ERROR
> {org.jaggeryjs.jaggery.core.manager.WebAppManager} -
> org.mozilla.javascript.WrappedException: Wrapped
> org.jaggeryjs.scriptengine.exceptions.ScriptException:
> org.apache.commons.fileupload.FileUploadException: the request was rejected
> because no multipart boundary was found (/publisher//index.jag#15)
> org.jaggeryjs.scriptengine.exceptions.ScriptException:
> org.mozilla.javascript.WrappedException: Wrapped
> org.jaggeryjs.scriptengine.exceptions.ScriptException:
> org.apache.commons.fileupload.FileUploadException: the request was rejected
> because no multipart boundary was found (/publisher//index.jag#15)
> at
> org.jaggeryjs.scriptengine.engine.RhinoEngine.execScript(RhinoEngine.java:582)
> at org.jaggeryjs.scriptengine.engine.RhinoEngine.exec(RhinoEngine.java:280)
> at
> org.jaggeryjs.jaggery.core.manager.WebAppManager.execute(WebAppManager.java:377)
> at org.jaggeryjs.jaggery.core.JaggeryServlet.doPost(JaggeryServlet.java:29)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
> at
> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
> at
> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
> at
> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
> at
> org.jaggeryjs.jaggery.core.JaggeryFilter.doFilter(JaggeryFilter.java:21)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
> at
> org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:177)
> at
> org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:161)
> at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
> at
> org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:57)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> at
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
> at
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
> at
> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1653)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
> Caused by: org.mozilla.javascript.WrappedException: Wrapped
> org.jaggeryjs.scriptengine.exceptions.ScriptException:
> org.apache.commons.fileupload.FileUploadException: the request was rejected
> because no multipart boundary was found (/publisher//index.jag#15)
> at
> org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1754)
> at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:148)
> at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:386)
> at
> org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:85)
> at
> org.jaggeryjs.rhino.publisher.c2._c_anonymous_1(/publisher//index.jag:15)
> at org.jaggeryjs.rhino.publisher.c2.call(/publisher//index.jag)
> at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
> at
> org.jaggeryjs.rhino.publisher.modules.c4._c_anonymous_9(/publisher/modules/goose.js:89)
> at
> org.jaggeryjs.rhino.publisher.modules.c4.call(/publisher/modules/goose.js)
> at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
> at
> org.jaggeryjs.rhino.publisher.modules.c2._c_callAPI_12(/publisher/modules/absolute.js:138)
> at
> org.jaggeryjs.rhino.publisher.modules.c2.call(/publisher/modules/absolute.js)
> at
> org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63)
> at
> org.jaggeryjs.rhino.publisher.modules.c2._c_anonymous_14(/publisher/modules/absolute.js:169)
> at
> org.jaggeryjs.rhino.publisher.modules.c2.call(/publisher/modules/absolute.js)
> at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
> at
> org.jaggeryjs.rhino.publisher.c2._c_script_0(/publisher//index.jag:199)
> at org.jaggeryjs.rhino.publisher.c2.call(/publisher//index.jag)
> at
> org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
> at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
> at org.jaggeryjs.rhino.publisher.c2.call(/publisher//index.jag)
> at org.jaggeryjs.rhino.publisher.c2.exec(/publisher//index.jag)
> at
> org.jaggeryjs.scriptengine.engine.RhinoEngine.execScript(RhinoEngine.java:577)
> ... 31 more
> Caused by: org.jaggeryjs.scriptengine.exceptions.ScriptException:
> org.apache.commons.fileupload.FileUploadException: the request was rejected
> because no multipart boundary was found
> at
> org.jaggeryjs.hostobjects.web.RequestHostObject.parseMultipart(RequestHostObject.java:425)
> at
> org.jaggeryjs.hostobjects.web.RequestHostObject.jsFunction_getAllFiles(RequestHostObject.java:229)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
> ... 52 more
> Caused by: org.apache.commons.fileupload.FileUploadException: the request
> was rejected because no multipart boundary was found
> at
> org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:954)
> at
> org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
> at
> org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
> at
> org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
> at
> org.jaggeryjs.hostobjects.web.RequestHostObject.parseMultipart(RequestHostObject.java:422)
> ... 58 more
>
>
> --
> Chan (Dulitha Wijewantha)
> Software Engineer - Mobile Development
> WSO2Mobile
> Lean.Enterprise.Mobileware
> * ~Email [email protected]*
> * ~Mobile +94712112165*
> * ~Website dulithawijewantha.com
> *
> * ~Blog blog.dulithawijewantha.com<http://dulichan.github.io/chan/>
> *
> * ~Twitter @dulitharw <https://twitter.com/dulitharw>*
>
--
*Ruchira Wageesha
**Associate Technical Lead** & Member, Management Committee, Development
Technologies*
*WSO2 Inc. - lean . enterprise . middleware | wso2.com*
*
email: [email protected], blog: ruchirawageesha.blogspot.com, mobile:
+94 77 5493444*
--
*Ruchira Wageesha
**Associate Technical Lead** & Member, Management Committee, Development
Technologies*
*WSO2 Inc. - lean . enterprise . middleware | wso2.com*
*
email: [email protected], blog: ruchirawageesha.blogspot.com, mobile:
+94 77 5493444*
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev