permaculture playing cards*
The moose likes EJB and other Java EE Technologies and the fly likes Upload files in EJB? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Upload files in EJB?" Watch "Upload files in EJB?" New topic

Upload files in EJB?

Long Hoang

Joined: Mar 09, 2011
Posts: 2
I am implementing a web application (an ecommerce website) . I use EJB for the app logic. Now I am facing a dilemma.

The app use JSF for presentation. Users will upload products they want to sell to the website. Each product can have many images. So now I have 2 Entities: Product and ProductImage. The images of their products will be stored on Amazon S3. Here is the flow:

1. User must fill the form (information of the product including product name, price, description, etc ...). Upload images and click submit.
2. Since the Product table in database uses an automatic incremented column as Primary key and I need that key to make image key, I must save product information to database first, then retrieve it from database and then call product.getId() to get the key. Then use that key as a part of the image key to upload that images to Amazon S3.
3. Use the keys of the images to make ProductImage entities. Call product.setImages(List<ProductImage> images) to update the product.
4. Use JPA to save the product to database.

I have two questions:
1. When use upload images, should I use just JSF for that or should I use EJB?
2. Is there any better way (algorithm) to solve the problem above? What's your approach?

Thank you!
K. Tsang

Joined: Sep 13, 2007
Posts: 2242

For upload files, most likely use JSF to get the "uploaded" file object then you can call EJB or another thread or whatever to actually write that file content to disk.

The algorithm you have seems fine, just make sure it is a single (all or nothing) transaction.

I agree. Here's the link:
subject: Upload files in EJB?
Similar Threads
JSF scalability and performance issues... please help... important
Manipulate Presentations Uploaded at Amazon S3 Storage Using REST APIs
Integrate Amazon S3 Storage with Saaspose REST APIs & Process Your Files
EJB and File Upload Download
Struts2 file upload problem