Displaying Images Stored In OPENSHIFT_DATA_DIR

2019-09-01 00:52发布

I have a non-scalable OpenShift app which uses the jbosseap cartridge and also has MySQL and PhpMyAdmin. I can upload and save image files to folders within the OPENSHIFT_DATA_DIR, e.g OPENSHIFT_DATA_DIR/appimages/uploaded.png but I have not been able to display the uploaded images with the HTML img tag.

There seem to be no way to get a correct path to images uploaded under OPENSHIFT_DATA_DIR. I ssh-ed into the server and found that OPENSHIFT_DATA_DIR, which evaluated to /app-root/data/ (actually /var/lib/openshift/5364c54ce0b8cd80180001f7/app-root/data/ ) was kinda outside the webroot of the app (where the ROOT.war was deployed to) which was /jbosseap/standalone/deployments/ROOT.war

So if the app runs from /jbosseap/standalone/deployments/ how can the app display images stored within OPENSHIFT_DATA_DIR which is /app-root/data/ since /app-root and /jbosseap are siblings of the same parent folder.

I just need to use HTML img tag to display an image uploaded and saved under OPENSHIFT_DATA_DIR e.g /appimages/uploaded.png since using src="/appimages/uploaded.png" for an img tag does not display the image.

1条回答
2楼-- · 2019-09-01 01:06

One solution could be write a Servlet that would read image from $OPENSHIFT_DATA_DIR and write it to OutputStream. Your servlet would be mapped to /images/* and would serve all images. You can also refer to this question How to configure static resources in jBoss AS 7

查看更多
登录 后发表回答