我正在使用extJS 4.2.1,我希望显示一个存储在ResponseBuilder中的PDF文件作为StreamingOutput对象。当响应返回到extjs控制器时,我不知道如何处理它以便在新页面上显示PDF。
@GET
@Path("/images/{imageNumber}/{imageType}")
@Produces({"application/pdf"})
public Response openDocument(@PathParam("company") String company,
@PathParam("imageNumber") String imageNumber, @PathParam("imageType") String imageType){
final File imageFile = new File("/someRemoteDir/28717484.pdf");
StreamingOutput stream = new StreamingOutput() {
public void write(OutputStream output) throws IOException, WebApplicationException {
try {
InputStream input = new FileInputStream(imageFile);
byte[] buf = new byte[8192];
int c = 0;
while ((c = input.read(buf, 0, buf.length)) > 0) {
output.write(buf, 0, c);
output.flush();
}
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
};
ResponseBuilder response = Response.ok(stream);
response.type("application/pdf");
response.status(200);
response.header("Accept-Ranges","bytes");
response.header("Cache-Control",null);
response.header("Pragma",null);
response.header("Content-Disposition","inline; filename=\"" + imageDoc.getNumber() +"\"");
return response.build();
}
extJS控制器
Ext.Ajax.request({
method: 'GET',
url: CTrack.Config.appPath('loads/images/' + imageNumber + '/' + imageType),
jsonSubmit: true,
success: function(response, opt) {
if (response.status == 200) {
NOT SURE WHAT TO DO HERE?.........
} else {
me.displayError(errorMsg);
} },
failure: function(response, opt) {
console.log('Failure');
}
...