One Star

Images in REST Post as multipart/form-data

Hi, I'm trying to do a rest post using 'tRESTRequest' component that accepts three info text type and one or more images, using "Content-Type: multipart/form-data". I don't know name and quantity of images, so I thought to manage parts of request body via java code in a 'JavaRow' component, but didn't find how to access to it (I tryed all globalMap items, also 'restRequest' child items).
I hope find variable, cast it as 'MultipartBody' and extract a map of multipart parts (name of the part is the key, InputStream representing the part - value), finally make it available to my java component following the 'tRESTRequest'.
Can anyone suggest me the best practice to solve this issue in Talend v5.4?
   
4 REPLIES
One Star

Re: Images in REST Post as multipart/form-data

If I POST a JSON or XML file, it work fine, so I parse input in 'XMLMap' component correctly
One Star

Re: Images in REST Post as multipart/form-data

Hi, I'm trying continue my REST post service with two field and two images, all optional. It work fine and dataflow goes into the post node only if I pass from client all four inputs, but if the client doesn't pass one or more inputs (all are NULLABLE = true as shown) the data flow doesn't go into the post node. 
Where I wrong, help me, thanks.
  
One Star

Re: Images in REST Post as multipart/form-data

For eample, if I don't pass 'img2' the flow try enter in POST node, but throw this excepion.
### LOG Talend ########################################################
Starting job MultipartTest at 09:57 13/03/2015.
connecting to socket on port 3979
connected
: org.apache.cxf.endpoint.ServerImpl - Setting the server's publish address to be
: org.eclipse.jetty.server.Server - jetty-8.1.14.v20131031
: org.eclipse.jetty.server.AbstractConnector - Started SelectChannelConnector@0.0.0.0:9095
: org.apache.cxf.jaxrs.utils.JAXRSUtils - No multipart with content id img2 found, request content type : multipart/form-data;boundary====1426237074497===
: org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper - javax.ws.rs.BadRequestException: org.apache.cxf.jaxrs.utils.multipart.MultipartReadException: No multipart with content id img2 found, request content type : multipart/form-data;boundary====1426237074497===
at org.apache.cxf.jaxrs.utils.SpecExceptions.toBadRequestException(SpecExceptions.java:82)
at org.apache.cxf.jaxrs.utils.ExceptionUtils.toBadRequestException(ExceptionUtils.java:109)
at org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils.getMultipart(AttachmentUtils.java:143)
at org.apache.cxf.jaxrs.provider.MultipartProvider.readFrom(MultipartProvider.java:168)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1258)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1205)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:756)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:715)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:252)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:88)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:65)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.cxf.jaxrs.utils.multipart.MultipartReadException: No multipart with content id img2 found, request content type : multipart/form-data;boundary====1426237074497===
... 30 more
############################################################################
One Star

Re: Images in REST Post as multipart/form-data

Hello, 
Is there any solution about this post ? 

thanks in advance, 
regards,