简体   繁体   English

通过 URL 从 Spring 应用程序访问 Azure bolb 存储中的图像时出现问题

[英]Problem accesing image in Azure bolb storage from Spring app via URL

I have an image in Azure blob storage and I need access to it within an Spring boot app in order to populate a Jasper report.我在 Azure blob 存储中有一个图像,我需要在 Spring 引导应用程序中访问它以填充 Jasper 报告。 In my local machine is working just fine, the code runs, gets the image and populates de reports but in my DEV environment it is not working.在我的本地机器上工作正常,代码运行,获取图像并填充报告,但在我的 DEV 环境中它不工作。

The DEV envionrment is basically an Azure VM with Nginx as reverse proxy, and docker to run the containers. DEV 环境基本上是一个 Azure VM,Nginx 作为反向代理,docker 运行容器。 The spring app is up and running there but when I try to get the image it is not working. spring 应用程序在那里启动并运行,但当我尝试获取图像时它无法正常工作。 I receive a FileNotFound exception.我收到 FileNotFound 异常。

However if I try to retrieve the image via a cUrl get i can download it form the VM and from the container itself.但是,如果我尝试通过 cUrl 获取图像,我可以从 VM 和容器本身下载它。 There are some company configurations and proxy but as I can access it from the container I think I should be able to access it from my java code as well...有一些公司配置和代理,但由于我可以从容器访问它,我想我也应该能够从我的 java 代码访问它......

The URL and ip are mapped in the hosts file in the docker container. URL和ip映射到docker容器的hosts文件中。

Does anyone has any idea what may be happening?有谁知道可能会发生什么? That I can retrieve the image from the container but not form the code?我可以从容器中检索图像但不能形成代码吗?

EDIT: Adding Stack trace from Jasper, pretty much the same when I open a stream in my own code.编辑:从 Jasper 添加堆栈跟踪,当我在自己的代码中打开 stream 时几乎相同。

2022-03-23 12:37:54.604 ERROR 1 --- [http-nio-8080-exec-9] n.s.j.engine.fill.JRFillSubreport : Fill 1: exception

net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error opening input stream from URL: https://MY_BLOB.blob.core.windows.net/images/explosive.png.
at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:139) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.InputStreamPersistenceService.load(InputStreamPersistenceService.java:51) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.DefaultRepositoryService.getResource(DefaultRepositoryService.java:196) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.RepositoryUtil.findInputStream(RepositoryUtil.java:195) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.RepositoryUtil.getBytesFromLocation(RepositoryUtil.java:211) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.renderers.util.RendererUtil.getNonLazyRenderable(RendererUtil.java:179) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:526) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:451) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:548) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummaryNoLastFooterSamePage(JRVerticalFiller.java:1265) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerticalFiller.java:1216) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVerticalFiller.java:308) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:126) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:622) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:433) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:830) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:61) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:221) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
Caused by: net.sf.jasperreports.engine.JRException: Error opening input stream from URL: https://MY_BLOB.blob.core.windows.net/images/explosive.png.
at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:343) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:122) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
... 21 common frames omitted
Caused by: java.io.FileNotFoundException: https://MY_BLOB.blob.core.windows.net/images/explosive.png
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1920) ~[na:na]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520) ~[na:na]
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250) ~[na:na]
at java.base/java.net.URL.openStream(URL.java:1165) ~[na:na]
at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:339) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]

Please check if any of the following ways can work.请检查以下任何一种方法是否有效。

This exception Error opening input stream from URL will be usually thrown by the FileInputStream, FileOutputStream.此异常Error opening input stream from URL通常由 FileInputStream、FileOutputStream 抛出。

  • FileInputStream is for files and not for URLs. FileInputStream 适用于文件而非 URL。

1.To get an input stream from any URL is via URL.openStream() , or URL.getConnection().getInputStream() , which is equivalent but you can have other reasons to get the URLConnection if required. 1.要从任何 URL 获取输入 stream 是通过URL.openStream()URL.getConnection().getInputStream() ,这是等效的,但如果需要,您可以有其他原因获取 URLConnection。

example:例子:

InputStream input = new
     URL("https://MY_BLOB.blob.core.windows.net/images/explosive.png").openStream();

See java - InputStream from a URL - Stack Overflow请参阅java - 来自 URL 的 InputStream - 堆栈内存溢出


  1. Try adding that image as an image resource in the main 'images' folder, then try to change that line of xml to be the following:尝试将该图像作为图像资源添加到主“图像”文件夹中,然后尝试将 xml 的那一行更改为以下内容:

jrxml File: jrxml文件:

    <imageExpression><![CDATA["https://...../images/explosive.png "]]></imageExpression>

Or或者

. . 3. Try to create the following parameters in reports to reference them later from absolute or external reference : java - Spring JasperReports Images Location - Stack Overflow 3. 尝试在报告中创建以下参数,以便稍后从绝对或外部参考中引用它们: java - Spring JasperReports 图像位置 - 堆栈内存溢出

This allows the images directory to be relative to the ROOT_DIR
path. It also allows you to change ROOT_DIR dynamically. The
parameters must be declared in their relative order.

    <imageExpression class="java.lang.String">
       <![CDATA[$P{ROOT_DIR}+"explosive.png"]]>
    </imageExpression>

Please check the below references.请检查以下参考资料。

References:参考:

  1. java - Using JasperReports with a relative path - Stack Overflow java - 使用具有相对路径的 JasperReports - 堆栈内存溢出
  2. Jasper: error opening input stream from url - Stack Overflow Jasper:从 url 打开输入 stream 时出错 - IT工具网
  3. java - How to show an image on jasper report? java - 如何在 jasper 报告中显示图像? - Stack Overflow - 堆栈溢出

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

相关问题 从 Azure 存储中获取 blob 时出现问题:Spring 启动 - Problem fetching blob from Azure Storage: Spring Boot 将文件从 azure web app 复制到 Azure Storage - Copy files from azure web app to Azure Storage 无法从 Azure Blob 存储检索图像 - Could not retrieve image from Azure Blob Storage 如何在Spring中从没有持续时间的云存储生成URL文件 - How to generate URL file from cloud storage without duration in Spring 如何从 Flutter 中的 Firebase 存储中检索图像 URL? - How to retreive a image URL from Firebase Storage in Flutter? 将 Base 64 字符串/图像上传到 Azure 存储图像出现空白 Spring 引导 - Uploading Base 64 String/Image to Azure storage image is coming out blank Spring boot 如何通过node.js从azure存储下载blob到本地存储? - How to download blobs from azure storage via node js to local storage? HTTP 触发器 azure function 从 blob 存储错误获取图像 - HTTP trigger azure function get image from blob storage error Flutter 从 firebase 存储中获取图像并在应用程序中显示以供下载 - Flutter get image from firebase storage and show it in app for download 如何从公共 azure 私人存储帐户连接到 azure static web 应用程序 - How to connect to a azure private storage account from a public azure static web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM