post multipart/formdata from node.js to irods

267 views
Skip to first unread message

Valentina Tedone

unread,
Dec 29, 2014, 5:19:22 AM12/29/14
to irod...@googlegroups.com
Hi!
I'm trying to make to post a file directly from the Node.js server to iRODS-REST using the form-data package of Node.js.
The request doesn't work.
We get this message:

WARN  org.jboss.resteasy.core.ExceptionHandler  - Failed executing POST /fileContents/biolabZone/home/xtensdevel/test.fcsv
org.jboss.resteasy.spi.ReaderException: java.lang.IllegalArgumentException: Failure parsing MediaType string: false
at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:183)
at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.irods.jargon.rest.auth.BasicAuthFilter.doFilter(BasicAuthFilter.java:106)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:701)
Caused by: java.lang.IllegalArgumentException: Failure parsing MediaType string: false
at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse(MediaTypeHeaderDelegate.java:113)
at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.fromString(MediaTypeHeaderDelegate.java:18)
at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$PartImpl.<init>(MultipartInputImpl.java:253)
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.extractPart(MultipartInputImpl.java:234)
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInputImpl.extractPart(MultipartFormDataInputImpl.java:64)
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.extractParts(MultipartInputImpl.java:229)
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.parse(MultipartInputImpl.java:198)
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataReader.readFrom(MultipartFormDataReader.java:52)
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataReader.readFrom(MultipartFormDataReader.java:20)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:59)
at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.readFrom(ServerReaderInterceptorContext.java:62)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:51)
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
at org.jboss.resteasy.security.doseta.DigitalVerificationInterceptor.aroundReadFrom(DigitalVerificationInterceptor.java:32)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:150)
... 28 more

The form is :

{ _overheadLength: 152,
  _valueLength: 0,
  _lengthRetrievers: [ [Function] ],
  writable: false,
  readable: true,
  dataSize: 0,
  maxDataSize: 2097152,
  pauseStreams: true,
  _released: false,
  _streams: 
   [ '----------------------------674345888574593946526399\r\nContent-Disposition: form-data; name="uploadFile"; filename="test.fcsv"\r\nContent-Type: false\r\n\r\n',
     { source: [Object],
       dataSize: 0,
       maxDataSize: Infinity,
       pauseStream: true,
       _maxDataSizeExceeded: false,
       _released: false,
       _bufferedEvents: [Object],
       _events: [Object] },
     [Function] ],
  _currentStream: null,
  _boundary: '--------------------------674345888574593946526399' } 

and my function where I make the request is:

saveOnIrods : function(id){
                      var request = require('request');
                      var fs = require('fs');
                      var FormData = require('form-data');
                      var filePath = "test.fcsv";
                      var form = new FormData();
                      var file = fs.createReadStream(filePath);
                      form.append('uploadFile',file);
form.submit({
host:'10.186.10.60',
port:8080,
auth:'xtensdevel:xtensdevel',
path:'/irods-rest-4.0.2.1-SNAPSHOT/rest/fileContents/biolabZone/home/xtensdevel/test.fcsv',
headers:form.getHeaders()
},
function(err, res) {
console.log(res);
});

}
};

Where is the problem??Any suggestions??

Thank you,

Valentina

Mike Conway

unread,
Dec 29, 2014, 8:39:59 AM12/29/14
to irod...@googlegroups.com
Hi Valentina,

The 'content type' of your 'form' is set to the string 'false'.  That seems odd.  should that not be some sort of multipart type?



  [ '----------------------------674345888574593946526399\r\nContent-Disposition: form-data; name="uploadFile"; filename="test.fcsv"\r\nContent-Type: false\r\n\r\n',

--
--
"iRODS: the Integrated Rule-Oriented Data-management System; A community driven, open source, data grid software solution" https://www.irods.org
 
iROD-Chat: http://groups.google.com/group/iROD-Chat

---
You received this message because you are subscribed to the Google Groups "iRODS-Chat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to irod-chat+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Valentina Tedone

unread,
Dec 29, 2014, 8:48:33 AM12/29/14
to irod...@googlegroups.com
Hi!

I don't set the content type set of my form. It is set by node.js. 
I tried to set the headers in this way:

 form.submit({
host:'10.186.10.60',
port:8080,
auth:'xtensdevel:xtensdevel',
path:'/irods-rest-4.0.2.1-SNAPSHOT/rest/fileContents/biolabZone/home/xtensdevel/test.fcsv',
headers:{'content-type':'multipart/form-data;boundary='+form.getBoundary(),'accept-encoding':'multipart/form-data'}
},
function(err, res) {
//console.log(res);
});


but I receive the same error!

;(

Valentina

Valentina Tedone

unread,
Jan 8, 2015, 6:46:19 AM1/8/15
to irod...@googlegroups.com
Hi Mike! 

I solved my problem.
The error was in the use of the Node.js function "createReadStream", in fact it sets the "content-type" to "false".
So I used another function "fileReadSync" that allows to set "content-type" to "multipart/formdata".


Reply all
Reply to author
Forward
0 new messages