0

I'm working on a Java web application. As part of this web app, I have a database containing objects with image file paths associated with them. By simply dragging and dropping, I was able to put these images in an images folder in my web server. Their path in Eclipse appears to be src/main/webapp/images.

When I want to access these images in a JSP page, I simply make an img tag with src="/images/fileName.png" and it works perfectly fine.

Here's the issue. I want users to be able to upload their own images to the web server, storing the filenames in the database. I've been looking around for a way to do this, but I'm having trouble finding a detailed answer. What can I use to write the images to that specific folder, images, in my web server? Thanks in advance.

For reference, here is an example of a fileName: /images/propane.png

And here is an example of me calling it in JSP: <img src="/images/propane.png">

I realize this may be a kind of basic question, but I'm really having trouble with getting the image to be stored in that specific directory.

jpabene
  • 129
  • 2
  • 13

1 Answers1

0

You need to be aware that anything uploaded to src/main/webapp/images will be deleted when you deploy a new version of your application to OpenShift. You can save and serve the images from the OPENSHIFT_DATA_DIR, which is the only directory you can write to that won't be deleted when you redeploy your application. You also need to be aware that the files in OPENSHIFT_DATA_DIR are not shared across gears in a scaled OpenShift application. So if your application is scaled, you need to store user uploaded images somewhere like Dropbox or Amazon S3.

For details on how to serve images from OPENSHIFT_DATA_DIR via your Java application, look at the answer to this question and this OpenShift tutorial.

Community
  • 1
  • 1
Mark B
  • 183,023
  • 24
  • 297
  • 295
  • Thank you very much! I'll look into those two links you provided and test them out. – jpabene Aug 12 '15 at 17:12
  • I tried the OpenShift tutorial and I got the following error: – jpabene Aug 12 '15 at 17:49
  • `/var/lib/openshift/l3tt3rsAndNumb3rs/app-root/data/quartermaster (No such file or directory)` – jpabene Aug 12 '15 at 17:49
  • Do you have any suggestions on how to proceed, or what might be causing this? – jpabene Aug 12 '15 at 17:49
  • @jpabene Did you SSH into the server and verify that the directory exists? It looks like you are trying to use a subdirectory named 'quartermaster', did you create that directory? `/var/lib/openshift/l3tt3rsAndNumb3rs/app-root/data/` would be the OPENSHIFT_DATA_DIR path if your app's name is 'l3tt3rsAndNumb3rs`. The quartermaster directory would not be there unless you create it. – Mark B Aug 12 '15 at 18:57