简体   繁体   中英

Unable to access static file in Node express root folder

I am trying to create a file uploader which will store file in stored_images directory as shown below:

/project
  /bin
  /stored_images
  /routes
  /public

After the file has been saved here, I want to send url of the saved file to my front-end javascript. How can I get the url of file in stored in stored_images directory?? Or is there other better way to do this??

First tell express where to look for static files.

app.use(express.static('public'))

Then put you images folder in your public folder. Then the url to your images would be the path from within the public folder to your images.

For example /my_images/cool_pic .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM