简体   繁体   English

使用不带套接字的Java将图像文件发送到客户端

[英]send image file to client using java without sockets

I am using file download phonegap in my client side (ipad) to download an image file from the internet. 我正在客户端(ipad)中使用文件下载phonegap从Internet下载图像文件。 Now I need to send the image through my java server. 现在,我需要通过Java服务器发送图像。 I am sending the image as stream , but the client side needs a file. 我将图像作为stream发送,但是客户端需要一个文件。 If I send the image file as stream it means it's not downloading the image file. 如果我以流形式发送图像文件,则表示它没有下载图像文件。 How do I send the image file as a file without using sockets ? 如何不使用sockets将图像文件作为文件发送?

My server side code is: 我的服务器端代码是:

String file_location=request.getQueryString();
String[] splitable=file_location.split("&");
String[] document_name=splitable[0].split("=");
String[] document_page=splitable[1].split("=");

PDFDocumentManag er documentManager;
try
{
    ServletOutputStream out = response.getOutputStream();
    //String location=loadClass.fileLocation(document_name[1]);
    String location="D:/Processing/893210.pdf";
    documentManager = new PDFDocumentManager(new File(location));
    documentManager.setPageNum(Integer.parseInt(document_page[1]));
    response.setContentType("image/gif"); 
    ImageIO.write(documentManager.getImage(), "gif", new File("D:/testing/out.gif"));
}

我不确定我是否正确理解您的问题,但是您可能需要“内容处置”尝试

response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

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

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