[英]CXF JAX-RS downloading resource from URL
I want to send across resource(say a image) from some URL to front-end. 我想跨资源(例如图像)从某个URL发送到前端。 The typical way of doing this is to create a File and build the response.
这样做的典型方法是创建一个文件并生成响应。 Is there any way in which I don't have to create the File in java code and still send the resource to front-end.
有没有什么方法可以不必用Java代码创建File并将资源发送到前端。
Front-end cannot access the URL due to some constraints. 由于某些限制,前端无法访问URL。 Currently the Pseudo code looks like this.
目前,伪代码看起来像这样。
File file = new File(fullPath);
FileUtils.copyURLToFile(url, file);
ResponseBuilder response = Response.ok(modulePDF);
I want to send content of URL to front-end without creating file. 我想不创建文件就将URL的内容发送到前端。 Is there any way?
有什么办法吗?
What way did have in mind to actually obtain the file without creating a File
object? 在不创建
File
对象的情况下实际上想到了哪种方式获取文件?
Not sure I fully understand the complete requirement, but you don't have to create a File
object. 不知道我完全理解完整的需求,但是你不必创建一个
File
对象。 You can send out a byte[]
, or simply write it to the response output stream by returning StreamingOutput
. 您可以发送
byte[]
,也可以通过返回StreamingOutput
将其简单地写入响应输出流。
@GET
public StreamingOutput getString() {
return new StreamingOutput(){
@Override
public void write(OutputStream out)
throws IOException, WebApplicationException {
// write to the `out` stream
}
};
}
For anything more than that, you will have to greatly elaborate on your requirement. 除此之外,您将不得不详细说明您的要求。 The information you've provided, (especially the highlighted line) doesn't quite paint a clear enough problem as to what actual problem is you are facing.
您提供的信息(尤其是突出显示的行)并不能完全解决您所面临的实际问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.