Hi,
First of all, I don't save my images in the database, they are saved on the
web server. Basically you need two http servlets, one for download and one
for upload. (Maybe you can do it with only one by just using GET and POST
but anyway...)
For uploading I use a fileUploader widget inside a form. A submit button
triggers uploadForm.submit() and the file sent to the httpServlet.
uploadForm.setEncoding(FormPanel.Encoding.MULTIPART);
uploadForm.setMethod(FormPanel.Method.POST);
uploadForm.setAction(GWT.getModuleBaseURL() +"ServletUpload");
...
The http servlet request is parsed to get the file and write it to the
webserver. I save my files in directories inside the WEB-INF folder because
it is private.
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(req);
...
For downloading all you need is an html img tag calling your downloadServlet
String serviceCall = GWT.getModuleBaseURL()
+"ServletDownload?url="+Constants.DOWNLOADPATH+fileName;
html.setHTML("<img src=\""+serviceCall+"\" />");
In your httpServlet for download, you take the url paramater from the
response, find the resource and then stream back to the browser as a
response using the ServletOutputStream:
String urlString = request.getParameter("url");
response.setContentType("image/jpg");
ServletOutputStream out = resp.getOutputStream();
URL url = getServletContext().getResource(urlString);
...
By using this approach you can stream an image in a private folder by using
the servlet call in the html tag to serve the image.
Hope this helps...
For more info you can investigate the concepts mentioned Trevis's and
Subhro's posts.
Ahmet
On Wed, Apr 21, 2010 at 7:55 AM, KK <[email protected]> wrote:
> Can you please show an example code .. how you made this work?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.