上载新文件时刷新dist目录 [英] Refresh dist directory when uploading new files
问题描述
我实际上是在使用Angular2和Node.js开发应用程序.
I'm actually developping an application using Angular2 and Node.js.
我从Angular-cli开始了Angular2部分.
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.
问题是,当我尝试显示此图像时,它们不显示.我需要重新运行"ng build"才能看到它们.我认为这是由于dist目录中不存在新上传的文件.
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.
-
文件上传后是否可以动态刷新dist目录?
Is there a way to dynamically refresh dist directory after the file upload ?
在上传过程中直接复制dist目录(还是资产目录)中的文件是正确的方法吗?
Is it a correct way to directly copy files in the dist (and still in assets) directory during the upload ?
祝你有美好的一天,
谢谢
推荐答案
资产文件夹是源代码.
dist文件夹正在编译结果,供应用程序运行时参考.
实际上,您可以上传到dist.
The assets folder is source code.
The dist folder is compling results, that for application run time reference.
Actually you can upload to dist.
但是我认为您创建用于上传文件的其他目录(例如 http://{domian}/upload/
)会更好.从根获取具有相对路径的图像.
But I think you create other directory (like http://{domian}/upload/
) for upload files will be better. get image with relative path from root.
您正在通过 ng serve
在本地上传文件,对吧?
Refenereces的两种方式:
1.尝试将dist部署到服务器,然后上传文件,您将获得映像.
2.使用 lite-server
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"
上传文件应位于dist/{upload}/{image} .jpg
The upload files should be in dist/{upload}/{image}.jpg
这篇关于上载新文件时刷新dist目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!