简体   繁体   English

在Angular 5中保存和读取图像的最佳实践是什么?

[英]What's the best practice for saving and reading image in Angular 5?

I've Angular 5 app with java rest services, the Java application saved images in a folder which is outside the java app. 我有带有Java rest服务的Angular 5应用程序,Java应用程序将图像保存在Java应用程序之外的文件夹中。 Now, the Angular suppose to read these images. 现在,Angular假定读取这些图像。 Because these images are shared by both applications, it make sense to save them outside but it doesn't work or not sure how to do it. 由于这两个应用程序共享这些图像,因此将它们保存到外部很有意义,但是它不起作用或不确定如何执行。

Example of scenario I have: The Java app saved images into: 我的场景示例:Java应用程序将图像保存到:

C:\Users\MyName\Documents\workspace\myentitiy

The Angular component has the following template: Angular组件具有以下模板:

<img [src]=imagesPath alt="">

The imagesPath declared inside the component: 在组件内部声明的imagesPath:

public imagesPath :any = "../myentitiy/1/myfiles/1/body.png";

My assets folder (which not include the images I need again as the requirement): 我的资产文件夹(不包含我再次需要的图像):

C:\Users\MyName\Documents\workspace\MyAngularApp\src\assets

I've tried to changes imagesPath to different path but couldn't make it to work, any idea how Angular can access files outside or I HAVE to change the Java application to save into the Angualr's assets folder? 我试图将imagesPath更改为不同的路径,但无法使其正常工作,你知道Angular如何访问外部文件,或者我必须更改Java应用程序以保存到Angualr的资产文件夹中吗?

Thanks. 谢谢。

What you are trying to do is wrong. 您尝试做的是错误的。 Think about the deployment. 考虑部署。 What you want to do is, 你想做的是

From the front-end, you can upload images. 您可以从前端上传图像。 Those image will be uploaded to the back-end, so that you can store the image in a particular folder inside a ftp server. 这些图像将被上传到后端,以便您可以将图像存储在ftp服务器内部的特定文件夹中。 Now, you can store the url of that image in the database. 现在,您可以将该图像的URL存储在数据库中。 When you are loading those images from the front-end, back-end sends you the image URLs loaded from the database. 从前端加载这些图像时,后端向您发送从数据库加载的图像URL。

Then you can show those images. 然后,您可以显示这些图像。

Keeping a shared location only works when you are developing your application, but not when you are deploying it. 保留共享位置仅在开发应用程序时有效,而在部署它时则无效。

For the development purposes, you may try to save all the images inside a folder, and store the URLs. 出于开发目的,您可以尝试将所有图像保存在一个文件夹中,并存储URL。 You can use Chrome Web Server to host images. 您可以使用Chrome Web Server托管图像。 This is only for the development purposes. 这仅出于开发目的。 Anyway, when you are deploying, you need to workout on image uploading part from your Java backend to the FTP server. 无论如何,在部署时,您需要对从Java后端到FTP服务器的图像上传部分进行锻炼。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM