wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes EJB and File Upload Download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB and File Upload Download" Watch "EJB and File Upload Download" New topic
Author

EJB and File Upload Download

Frankie Fuentes
Ranch Hand

Joined: Mar 28, 2010
Posts: 41
Hi everyone,

I have this requirement to be able to upload photos that will be tied to a particular product. I've taken the filesystem approach in which the images are stored in a filesystem rather than in a database. Here's my algorithm for saving a product and saving its associated images to the filesystem and its reference to the database.

1. Create new Product instance (web tier)
2. Read uploaded images (web tier)
3. For each uploaded images, create an Image instance and assign a URL referencing the uploaded image (web tier)
4. Save uploaded images in the filesystem using the assigned URL (web tier)
5. Call an EJB method passing the new Product instance, and associated Image instances with assigned URLs referencing the uploaded images saved in the filesystem (EJB)
5.1. EJB then persists the Product instance and associates the Image instances. (EJB)

My question is what is the better approach in deleting the Product and its associated Image instances? I mean, how am I supposed to delete the image files being referenced by the Image instances from the filesystem if we're not supposed to create, modify, or delete files from a filesystem within EJB method?

The first thing that occurred to me is to return the deleted Image instances to the web tier and let the web tier delete the image files it is referencing from the filesystem. I just thought that it looks ugly. Is there any better approach than this? Most of my delete operations do not return the instances they've deleted.


Much appreciated

 
GeeCON Prague 2014
 
subject: EJB and File Upload Download