How To Serve Uploaded Images From OpenShift DATA_D

2019-02-25 09:44发布

问题:

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.

回答1:

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