Refresh dist directory when uploading new files

╄→гoц情女王★ 提交于 2020-01-06 17:58:37

问题


I'm actually developping an application using Angular2 and Node.js.

I started the Angular2 part with Angular-cli.

I have an issue concerning file upload. In the application, I can create Albums. In the Album form, there is a file input. In the backend, I store files, actually images, in a files directory in my assets.

The problem is, when I try to display this images, they don't display. I need to re-run "ng build" to see them. I assume this is due to the fact this newly uploaded files are not present in the dist directory.

  • Is there a way to dynamically refresh dist directory after the file upload ?

  • Is it a correct way to directly copy files in the dist (and still in assets) directory during the upload ?

Have a good day,

Thanks


回答1:


The assets folder is source code.
The dist folder is compling results, that for application run time reference.
Actually you can upload to dist.

But I think you create other directory (like http://{domian}/upload/) for upload files will be better. get image with relative path from root.

You are upload files in local via ng serve, right?
Two ways for your refenereces:
1. try to deploy dist to server, then upload files, you will get the images.
2. using lite-server

$ npm i -g lite-server
$ ng build --watch
$ lite-server --baseDir="dist"

The upload files should be in dist/{upload}/{image}.jpg



来源:https://stackoverflow.com/questions/43788923/refresh-dist-directory-when-uploading-new-files

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