Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在angular中通过URL访问资产文件夹中的图像_Angular_Spring Boot - Fatal编程技术网

在angular中通过URL访问资产文件夹中的图像

在angular中通过URL访问资产文件夹中的图像,angular,spring-boot,Angular,Spring Boot,在生成发票的PDF文件时,我试图在Spring后端使用Angular应用程序中的徽标 invoice.logo.url= 该图像没有显示在PDF上,但当我上传到imgur.com时,它就可以完美地工作了 手动转到url有时会显示图片,但有时会出现以下错误: Error: Cannot match any routes. URL Segment: 'assets/gfx/img/logos/rkmteam-logo.png' 如何访问外部应用程序中的图像?我不想依赖第三方网站(imgur等)。您

在生成发票的PDF文件时,我试图在Spring后端使用Angular应用程序中的徽标

invoice.logo.url=

该图像没有显示在PDF上,但当我上传到imgur.com时,它就可以完美地工作了

手动转到url有时会显示图片,但有时会出现以下错误:

Error: Cannot match any routes. URL Segment: 'assets/gfx/img/logos/rkmteam-logo.png'

如何访问外部应用程序中的图像?我不想依赖第三方网站(imgur等)。

您必须将图像转换为base64字符串,并将其添加到您的PDF发票中


要将图像转换为base64,请检查:

如果我理解正确,则Springboot应用程序需要访问Angular应用程序以检索图像

要实现这一点,您需要确保图像可以通过Angular中的
/assets
文件夹公开访问。验证
angular.json
文件以确保正确设置

话虽如此,我不推荐这种循环设置。理想情况下,后端应该是前端不可知的,但您会使其成为一个硬依赖


相反,我会考虑在Springboot举办标志。如果不可能,我会考虑用Base64对徽标进行编码,并以这种方式将编码字符串传递给Springboot。

为什么它有时有效,而不是一直有效?仅仅通过URL?我不知道为什么,但好的方法是将图像转换为Base64,然后将其添加到pdf中。