Forums Register Login

Upload files in EJB?

+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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.
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1373 times.
Similar Threads
JSF scalability and performance issues... please help... important
Integrate Amazon S3 Storage with Saaspose REST APIs & Process Your Files
Struts2 file upload problem
Manipulate Presentations Uploaded at Amazon S3 Storage Using REST APIs
EJB and File Upload Download
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:29:37.