pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alejandro Vilar" <alejandro.vi...@synacom.com.bo>
Subject RE: How to post file by pivot.
Date Fri, 11 Jun 2010 02:50:33 GMT
Hi Ken, as Greg mentioned in Pivot 1.5 there is a new class for files
manipulation related to web queries (FileSerializer).

You can try something like this on client side:

import java.io.File;
import java.net.URL;
import org.apache.pivot.io.FileSerializer;
import org.apache.pivot.web.*;

String hostname = "fileserver.com";
try {
    File fileToSend = new File("sample.jpg");
    PostQuery postQuery = new PostQuery(hostname, "/files");
    postQuery.getParameters().put("filename", fileToSend.getName());
    postQuery.setSerializer(new FileSerializer());
    URL url = postQuery.execute();

    GetQuery getQuery = new GetQuery(hostname, url.getPath());
    getQuery.setSerializer(new FileSerializer());
    File receivedFile = (File) getQuery.execute(); 

} catch (QueryException e) {
Hope this helps,

-----Original Message-----
From: kenjiang@sz.murata.com.cn [mailto:kenjiang@sz.murata.com.cn] 
Sent: Jueves, 10 de Junio de 2010 10:14 p.m.
To: user@pivot.apache.org
Subject: Re: How to post file by pivot.

Hi Greg,

Thank you for your information.
For post parameter is ok.But I would like to post arbitrary file like some
JPG,GIF to existing web server.
For Example,
1.User select the files.
2.Post to server side JSP.
3.Save files in server side.

In normal web application,we easily to do that.
I also use HTTPCLIENT to similar this action.It's Ok.
but is there simple way to use pivot function do that?I wouldn't like
include many third party lib in clinet JAR.
Since they may effect the loading applet time.

Best regards,
Ken Jiang

Murata Electronics Trading  (Shenzhen) Co.,Ltd




    Re: How to post file by pivot.



    Greg Brown











    Please respond to user




The easiest way to execute an HTTP POST in a Pivot application is by using
the org.apache.pivot.web.PostQuery class. Here are a couple examples:



The first one is a simple application that demonstrates unit testing a REST
service using web queries. The second one is a complete REST client
application. It will be part of the Pivot tutorial for Pivot 1.5.1. The
tutorial documentation does not exist yet, but the code should work OK.

Let me know if you have any questions about either example. Note that they
both use JSONSerializer to send and receive data - if you need to post
arbitrary file content, you may want to consider using an instance of
org.apache.pivot.io.FileSerializer instead.


On Jun 8, 2010, at 11:22 PM, kenjiang@sz.murata.com.cn wrote:

> Hi All,
> Is there any example for post file and parameter to web server by pivot.
> I check the pivot API doc,but seems pivot 1.5 can't do that.
> Does we need use our custom API do it like (Apache httpclient)?
> Please advise.
> Best regards,
> Ken Jiang
> *******************************************
> Murata Electronics Trading  (Shenzhen) Co.,Ltd
> Tel:86-755-82847251
> E-mail:kenjiang@sz.murata.com.cn
> *******************************************

View raw message