3

My app runs on JBoss EAP and I want to upload images to the OPENSHIFT_DATA_DIR and then save their relative paths in the MySQL DB because I need to construct a path to the images and later serve them to the browser when needed.

If my OPENSHIFT_DATA_DIR path is /var/lib/openshift/5364c54ce0b8cd80180001f7/app-root/data/ and I want schoolpics/federaluniversity/uniben-1/ inside it to save a file logo.png such that the full path will be

/var/lib/openshift/5364c54ce0b8cd80180001f7/app-root/data/schoolpics/federaluniversity/uniben-1/logo.png

How to achieve this in term of storing in database, and opening using URL of image in a web page, since the OPENSHIFT_DATA_DIR seems to be outside the webroot of the app.

MarmiK
  • 5,639
  • 6
  • 40
  • 49
Odili Charles Opute
  • 331
  • 2
  • 4
  • 13

1 Answers1

0

My solution to this issue was to create a servlet that would serve the images from the OPENSHIFT_DATA_DIR, the servlet also supplies a way to write the images to the OPENSHIFT_DATA_DIR also, you can check out this forum post for more information: https://www.openshift.com/forums/openshift/how-to-upload-and-serve-files-using-java-servlets-on-openshift

  • Thanks. First I have a failed attempt to move a file (uploaded to tmp) to schoolpics/federaluniversity/uniben-1/ within OPENSHIFT_DATA_DIR. The code log is here http://ur1.ca/hi8pd – Odili Charles Opute Jun 11 '14 at 20:08
  • Did you create that directory before you tried to move the image to it? –  Jun 11 '14 at 20:16
  • I have confirmed that the directory paths are created. It seems moving the uploaded file is what fails. – Odili Charles Opute Jun 13 '14 at 12:31
  • 1
    The images are now saved to a folder called logos within the OPENSHIFT_DATA_DIR, but I need to display them in an Ajax client. I tried www.theappurl.com/logos/logo1.png and got a 404 response page. Is there a way to construct a path to the uploaded images, since OPENSHIFT_DATA_DIR is outside the webroot? – Odili Charles Opute Jun 16 '14 at 14:24
  • I am having a similar problem. I have exposed my data dir using a handler in Undertow, but when I try to access my files, I get a 404. The server log points out `WFLYCTL0180: Services with missing/unavailable dependencies`. – Douglas De Rizzo Meneghetti May 20 '16 at 21:20