且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

角度找不到上载的图像

更新时间:2023-11-17 11:39:16

这可能是您的解决方案:

This might be a solution for you:

对于实时应用程序,您可能希望将图像保存在文件服务器上(例如Amazon AWS上的AWS S3),并将此文件的链接存储在数据库中.

For a live application you probably would want to save your images on a fileserver (for. example AWS S3 on Amazon AWS), and store the link to this file in a database.

对于您的本地主机项目,您可以使用 http服务器充当此文件服务器或者您可以将表达框架用于您的节点应用程序.

For your localhost project you can use http-server to function as this fileserver or you can use the express framework with ur node application.

npm install http-server -g
http-server C:/link/to/a/folder/you/have/saved/the/images/in

然后,您必须将链接保存到文件(在db(数据库)中或在文本文件中).为此,我建议您设置一个本地 MongoDB数据库.您可能需要花费一些时间才能进入,但这是很好的学习经验.您可以使用 https://mongoosejs.com/与您的节点应用程序进行通信.

Then you must save the link to your file, either in a db (database) or inn a textfile. For this I would recomend that you setup a local MongoDB database. This might take some time for you to get into, but it is good learning experience. You can use https://mongoosejs.com/ to communicate with your node application.

然后,当您上传新图像时,会将其从前端Angular应用程序发送到后端节点/express应用程序,将文件保存在文件夹中,并将链接保存在数据库中.使用https服务器,您将能够立即访问图像(可能会有som延迟).借助存储在数据库中的链接,您可以在每次刷新应用程序时通过http get请求将数据库中的数据发送到前端.

Then when you upload a new image, you send it from your frontend Angular app, to your backend node/express application, save the file in the folder and save the link in the db. With the https-server you will be able to access the image right away (with maybe som delay). And with the links stored in the db you can send the data in the db to your front end with a http get request whenever you refresh your application.

我希望这会帮助您实现目标:)

I hope this will help you to reach your goal :)