1

I have implemented an image uploading functionality. The problem is that I am saving these files outside an application (so that they won't be deleted in case of redeploy), and I don't really know how to refer them from a jsp file then, as I only know how to refer to the webapp (or resources) directory.

Cœur
  • 37,241
  • 25
  • 195
  • 267
fryzjerro
  • 99
  • 1
  • 3
  • 13
  • @IddoE Not really, as in that question files are stored within an app directory. – fryzjerro Sep 14 '17 at 23:44
  • and in your question where files are stored ? CDN ? same server other directory ? if so you should add full path, please save us for asking questions and provide as much information as you can ;) – whoopdedoo Sep 14 '17 at 23:50
  • I've said that files have been stored outside the application, in an external folder. To be specific, it is the tomcat directory, and it's the same for every server. – fryzjerro Sep 14 '17 at 23:58
  • too long for comment i'll add an answer, btw tomcat tag would be nice – whoopdedoo Sep 15 '17 at 00:01

1 Answers1

1

Have you tried adding to server.xml under $CATALINA_HOME/config/server.xml

<Context docBase="/usr/local/tomcat/folder/with/images" path="/uploads/img" />

For example:If you have foo.jpg inside the

/usr/local/tomcat/folder/with/images directory

then you can access the foo.jpg file via

localhost:8081/uploads/img/foo.jpg

whoopdedoo
  • 2,815
  • 23
  • 46
  • This would be nice, although it isn't universal. Is there a way to use $CATALINA_HOME instead of /usr/local/tomcat/? – fryzjerro Sep 15 '17 at 00:09
  • 1
    yes, you'll need to edit tomcat/startup.sh take a look https://stackoverflow.com/a/23957805/2655092 – whoopdedoo Sep 15 '17 at 00:20
  • This is too messy in my opinion then. But you're saying that there's no possibility to access external directories (from jsp) without changing the tomcat configuration, right? This makes me sad. – fryzjerro Sep 15 '17 at 00:25
  • 1
    yup, ur jsp is locked inside tomcat's scope or open another tomcat (or other server on the same machine) to provide static files (try nodejs, y not..) – whoopdedoo Sep 15 '17 at 00:26
  • I think I'll change the methodology then. Either to store files in db or pass them directly into jsp (as an array or bytes or smth). – fryzjerro Sep 15 '17 at 00:46
  • 1
    @fryzjerro storing base64 in key value database sounds good but also using CDN like aws s3 might be better – whoopdedoo Sep 15 '17 at 10:45
  • Ok, thank you very much for your help ;) I'ma consider every option ;) – fryzjerro Sep 15 '17 at 14:04
  • no problem, please approve my answer if it helped & to close the question :) – whoopdedoo Sep 15 '17 at 18:32