上传新文件时刷新 dist 目录 [英] Refresh dist directory when uploading new files

查看:26
本文介绍了上传新文件时刷新 dist 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上是在使用 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(并且仍在assets)目录中的文件是否正确?

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

祝你有美好的一天,

谢谢

推荐答案

assets 文件夹是源代码.
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 在本地上传文件,对吗?
两种方式供您参考:
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆