You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Brendan cheng <cc...@hotmail.com> on 2012/06/12 06:45:28 UTC

How to use pivot post to upload file in form of MULTIPART_FORM_DATA_TYPE?

Hi,
I want to upload a file from pivot client to server. And my server is setup to accept MULTIPART_FORM_DATA_TYPE.
I don't know how to achieve in Post method from pivot.It is like pivot doesn't have special function for dealing it.
Please advise!
Brendan

 		 	   		  

Re: How to use pivot post to upload file in form of MULTIPART_FORM_DATA_TYPE?

Posted by Sandro Martini <sa...@gmail.com>.
Hi,

> I wish I would know vertx.io earlier.  it looks good.
Yes, looks good even to me ... but I did only some "Hello World"-like
tests :-) ...

> I just invest couple weeks of time in Node.js and I may not be able to switch to vertex.io soon.
I imagine it. And even switch on a Java 7 infrastructure (vertx.io
needs it) on the server side could not be appliable now.

> What is downsize you found on Node.js?
I read some article related to how (bad) Node.js seems to handle
multithreading-related things (but don't know if/how it's good).
And I don't like so much Javascript generally speaking (but this is my
personal taste here) because if the system if small dynamic languages
are great, but as they grow in size/complexity usually things become
hard.
To me the real issue for me on Node.js (and Rails and others) is that
it's not based on the JVM infrastructure, but of course sometimes this
could not be so bad :-) ...

So nothing real in my experience against Node.js, don't worry ...

> I really wish to improve my system a little bit.
Yes, good luck for this.

For the server-side part I'm doing some experiments/small prototypes
even with the Typesafe Stack (Scala + Akka + Play 2) and they look
great, and probably they are the state of the art now ... but they are
not-so-simple. Just as another idea ...


Keep us updated, and if/when you have something to show us, post here :-) .

Bye,
Sandro

Re: How to use pivot post to upload file in form of MULTIPART_FORM_DATA_TYPE?

Posted by ccp999 <cc...@hotmail.com>.
Hi,

I wish I would know vertx.io earlier.  it looks good.
I just invest couple weeks of time in Node.js and I may not be able to
switch to vertex.io soon.

What is downsize you found on Node.js?

I really wish to improve my system a little bit.

Brendan

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/How-to-use-pivot-post-to-upload-file-in-form-of-MULTIPART-FORM-DATA-TYPE-tp4021907p4021915.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: How to use pivot post to upload file in form of MULTIPART_FORM_DATA_TYPE?

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
I'm sorry but on Jersey I can't help you so much ...

On the server side (speaking absolutely from a personal and subjective
point of view) I'd not use Node.js, but instead other (more
JVM-centric) frameworks ... some week ago I discovered this (probably
the most jvm-centric framework closer to node.js):

http://vertx.io/

Otherwise I'd use Grails or Play (or Lift), or Wicket on the server
side ... all these should have utility classes for transformation of
pojo from/to json, xml, etc ...


One of the things I'd like to improve in Pivot (maybe for 2.1) is the
extensibility for our existing Serializers.
Ideas, comments, etc as always are welcome.


Hope this helps (at least a little).

Bye,
Sandro

Re: How to use pivot post to upload file in form of MULTIPART_FORM_DATA_TYPE?

Posted by ccp999 <cc...@hotmail.com>.
Thanks Sandro,

Actually, I tried to use Jersey client to perform file upload but there is a
problem for the control name.
Node.js express server doesn't recognized the control name of the file to be
passed from Jersey.

let say you have a javascript html like this:

'<html>' + '<head>' + '<meta http-equiv="Content-Type" ' +
'content="text/html; charset=UTF-8" />' + '</head>' + '<body>' + '<form
action="/upload" enctype="multipart/form-data" ' + 'method="post">' +'<input
type="file" name="thumbnail" multiple="multiple">' + '<input type="submit"
value="Upload file" />' + '</form>' + '</body>' + '</html>'; 

and it will upload a file you selected to server but the equivalent Jersey
code failed to present the control name, in this case is "thumbnail" which
could cost some trouble from server side to retrieve the file.  I use a
non-standard way to resolve the issue. 

My client side code like this:

import java.io.File file;
com.sun.jersey.api.client.Client c =
com.sun.jersey.api.client.Client.create(config);
FormDataMultiPart form = new FormDataMultiPart();
form.bodyPart(new FileDataBodyPart("thumbnail", file)); 
String s = c.resource("127.0.0.1").path("upload")
.type(MediaType.MULTIPART_FORM_DATA)
.accept(MediaType.APPLICATION_JSON).post(String.class, form);

The reason I use Jersey because it also support java object marshaling to
Json or xml and unmarshaling.  So you can have Java web server and Pivot
client with Jersey being the middle man for the java POJO transferring.

Unfortunately, I added Node.js as the web server in between for doing other
jobs and that's I have the incompatibility.

Hope someone have a better solution!
 
Brendan

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/How-to-use-pivot-post-to-upload-file-in-form-of-MULTIPART-FORM-DATA-TYPE-tp4021907p4021910.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: How to use pivot post to upload file in form of MULTIPART_FORM_DATA_TYPE?

Posted by Sandro Martini <sa...@gmail.com>.
Hi Brendan,
sorry, this is an old question (look here for example:
http://apache-pivot-users.399431.n3.nabble.com/File-upload-per-rfc-1867-td2667943.html
) ... in short I think that the best option is to use some library to
simplify/implement the file upload in the full RFC way, using
something like the Apache HttpClient, and maybe even Apache Commons
FileUpload at Server-side.

Then, wrap it inside a PostQuery() , change the request mime type to
that required by your server, etc ... but at this point I don't know
if Pivot PostQuery add a great value to your request.

Some info here:
http://stackoverflow.com/questions/2304663/apache-httpclient-making-multipart-form-post


Probably File Upload (in a full rfc implementation) it's something
that we could try enhance in core Pivot (at least in Demos, or in a
wiki page), so if you have something to share with us, please do it.
But usually we don't want to introduce new dependencies, so we have to
see if/how to do (could be something for apache-extras).


Keep us updated.

Bye