Where to place images and other components folder in loopback?

点点圈 提交于 2019-12-13 03:56:17

问题


I want to add blog images and documents specific folder and get access to files in project, where should i make this folders and how can access in front end? I've tested images folder on common, server and project root folder but I couldn't access by something like : http://localhost:3000/logo.jpg or http://localhost:3000/images/logo.jpg


回答1:


As mentioned here in the docs you should use storage component. you may define a data source targeting your local file system and should set the directory you want to serve the files from in that. Data source configuration in file datasources.json might look like this:

  "files": {
    "name": "files",
    "connector": "loopback-component-storage",
    "provider": "filesystem",
    "root": "./client/storage"
  }

Also you need a container model with above "files" set as dataSource. Then you can access static files through the REST API described here



来源:https://stackoverflow.com/questions/47732182/where-to-place-images-and-other-components-folder-in-loopback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!