Advice needed - Storing images

Hello all,

I'm developing e-commerce application, and I have dilema where to store product photographs.

When I started learning struts and servlets/jsp, I stored photographs as BLOB in MySQL database, and hadnt any problems to do it this way.

For administrator purposes, I created admin interface. Administrator was able to insert new products into database, and in that case inserting product photos was implemented using form file, uploading photos directly from his local computer as BLOB object.

On the other hand, this system will probably damage the performance of web appliacation, so the idea I like more at the moment is using hypelinks.

My problem with hypelinks is - where to store photos? Photographs probably have to be stored somewhere on server, but in that case I would have to give some privilegies to administrator of web site and to allow him to access the server, and I dont want to do that.

Am I missing something here?

Thanks in advance,

Djordje

[1024 byte] By [djordjewa] at [2007-11-27 1:30:45]
# 1
Change the admin interface so that the photos will be stored as file in a directory instead of as BLOB in a database. And change the ImageServlet (if any) so that it loads the photos from the directory instead of from the database. Or isn't that what you need to know?
BalusCa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for quick response Balus, but few more questions please.1.In that case I would save file location as String in database, right?2.Where this directory would be?
djordjewa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

1) You can do. Save the filename and eventually the path.

2) This doesn't matter, it's your design choice. Keep accessibility, usability and portability in mind. You can store it in /WebContent/images (accessible directly by a simple request URI and high portable), or in /WebContent/WEB-INF/images (accessible by "ImageServlet" only and high portable), or even in c:/images (accessible by "ImageServlet" only and less portable) or so.

BalusCa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Thank you very much, everything's cleared now ;)
djordjewa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Almost all actually :(

Now I have difficulties with the path. Here is the code I use:

...

ServletContext appServletContext = this.getServlet().getServletContext();

String realPath = appServletContext.getRealPath("/images");

FileOutputStream fos = new FileOutputStream(realPath+"\\" + uploadForm.getFile().getFileName());

...

What I get for realPath is

...\build\web\images

and I would like to get

...\web\images

Any thoughts?

Sorry if this have been answered already, but in 100s of threads related to struts upload, I couldnt find the answer.

djordjewa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
anyone, please? :(
djordjewa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
I think you'd need to replace "/" to "\" using replace('/', '\')What are you getting if you get the realpath like below("/WEB-INF/images"); ?
skp71a at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Do not replace forward slashes by backward slashes whatsoever. The forward slash not only works in Windows, but also in UNIX systems while the backward slash doesn't. And when using backward slashes anyway, you have to escape them. Use forward slashes all the time.
BalusCa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Thanks for your response.

I don't think it has anything to do with '/' or '\' though.

My directories structure is following:

Web Pages

- META-INF

- WEB-INF

- images - this is the destination I would like to store my images

- etc, etc

In my NetBeans project I have following folders:

'build', 'conf', 'dist', 'nbproject', 'src', 'test' and 'web',

and after execution of my upload action, images are stored in 'build' folders, which has following structure:

-build

--web

META-INF

WEB-INF

images

etc, etc

Obviously I would like to store them in my 'web' folder, but just cant get there.

I hope this clears the picture about my problem bit more.

djordjewa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Then, inside Netbeans, set the WebContent root to the 'web' folder instead of the 'build' folder.I don't know how to do however, I use Eclipse-based IDE's only.
BalusCa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
Thanks once again, Balus, much appreciated.
djordjewa at 2007-7-12 0:32:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...