For a web application I am using Python/Flask as backend API service and VueJS for frontend application. I have uploaded an image file from VueJS application into Flask application's static folder through Axios and stored that filename into my database for further reference. How can I access that file back into my VueJS application using filename through API.
1 Answers
How on Earth these are freely exposed?
That's how your flask's server(I assume Werkzeug) is configured. Through configuration you tell the server that " hey look, these are the list of endpoints I want you to treat as APIs . But if you get requests which match this regex (./[templates|static]/ then these are the folders theyre contained as static files, serve them blindly
I would highly recommend digging deep into the history of servers, right from static servers which just served HTML, to CGI(Common gateway interface), to WSGI (pertains to python). Understand what it means to "comply" to WSGI spec. Then probably checkout apache httpd, nginx, etc and try learn how these are different from the likes of gunicorn, Werkzeug etc
Are there any more secure and Pythonic solutions?
I'd say base64 encode the image file name and store it in an object storage (s3, google storage), and write the backend logic to pick out the filename from the URL, base64 encode it, and fetch it from s3...and well, serve
Ofcourse there would be many other ways to do it

- 410
- 2
- 15
-
Previous I stored on Firebase Storage, but now the requirement is changed to local storage and now I am clueless with this situation. When both backend and frontend running on same server there is no such issue. But now it's got tricky for me. – Jitendra Dec 27 '21 at 08:41
-
why is it tricky? – D.B.K Dec 27 '21 at 08:51
-
I am feeling tricky to expose image files stored in one server to the other server using APIs. If they are on the same server I used to expose them with the help of send_from_directory method of Flask with restricted access. – Jitendra Dec 27 '21 at 08:58
-
what are the two servers for? – D.B.K Dec 27 '21 at 13:30
-
I mean frontend and backend are hosted on two different servers. – Jitendra Dec 28 '21 at 03:16