从字节数组加载图像内容

Loading Image content from an array of byte

我有一个重新运行的 REST 服务 byte[] 我喜欢创建一个图像(Ext.Img),其内容是服务结果

服务

@RequestMapping(value = "/retrieve_thumbnail", method = RequestMethod.GET)
public byte[] retrieveBDocumentThumbnail(@RequestParam String modelName,@RequestParam String modelVersion) throws BdocWebAccessException {
    return service.retrieveBDocumentThumbnail(modelName, modelVersion);
}

图片

 Ext.create("Ext.Img", {
     src:'tablet/bDocument/retrieve_thumbnail?modelName=MODELE_INT_003_TYPES_DONNEES&modelVersion'
})

服务已调用,但我在 javascript 控制台中收到此消息:

Resource interpreted as Image but transferred with MIME type text/plain: "http://localhost:8080/bdoci-tablet/tablet/bDocument/retrieve_thumbnail?modelName=MODELE_INT_003_TYPES_DONNEES&modelVersion".

我认为问题与格式有关,我该如何解决?

MIME 类型是一个 HTTP header,表示文件的类型。在这种情况下,它正在发送 text/plain。它应该表明这是一张图片。我不认为你的问题出在客户端,而是客户端响应了服务器端的无效响应。

 @RequestMapping(value = "/retrieve_thumbnail", method = RequestMethod.GET, 
        produces = MediaType.IMAGE_PNG_VALUE)