upload and download of images with Tomcat

W

Wojtek

Hello,

I try to upload images for futher download (as in a image
gallery) to a folder under web application dir. Everything goes
fine except one thing: the uploaded images are not seen
in the application till next deployment
of the application (Tomcat does not see the images).

Is it possible to make Tomcat see dynamically added
static content? I know that one of the solution is using
web server for serving static resources, but I would
like to find a solution in Tomcat.

Best regards,

Wojtek Stanczuk
 
M

Manish Pandit

Hello,

I try to upload images for futher download (as in a image
gallery) to a folder under web application dir. Everything goes
fine except one thing: the uploaded images are not seen
in the application till next deployment
of the application (Tomcat does not see the images).

Is it possible to make Tomcat see dynamically added
static content? I know that one of the solution is using
web server for serving static resources, but I would
like to find a solution in Tomcat.

Best regards,

Wojtek Stanczuk

The webserver solution is the best one IMO, however, if you want a
tomcat based solution, then you'd have to read the uploaded files in
the servlet/action, after persist them on the file system (which I
believe you're doing currently). However, to render them, read them
back from that location and write the output on the response. That
location can be a preference/property for the application.

Something like:

byte[] bytes =
FileUtils.readFileToByteArray(your_file_as_java_io_File); //Apache
Commons IO
response.setHeader("Content-Disposition", "attachment; filename=
\""+name_of_the_file+"\"");
response.setContentLength(bytes.length);
response.setContentType(resolve_content_type_based_on_extension);
response.getOutputStream().write(bytes);
response.getOutputStream().flush();
response.getOutputStream().close();

However, I find Apache+PHP much better for this kind of thing :)

-cheers,
Manish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top