【发布时间】:2017-09-29 01:59:32
【问题描述】:
我有一项服务,它向文件添加一些属性并将其作为字节数组在响应中发送回,但我很难显示它,因为它是字节,我试图将它转换为 base64 但它仍然没有工作.它显示原始字节
�PNG
IHDR&��LCv�IDATx��......
解决这个问题的最佳解决方案是什么,也许我应该更改响应类型是否可以不发送字节?
@RequestMapping(path = "image/decode", method = POST, consumes = "multipart/form-data", produces = {"image/png", "image/jpeg"})
public byte[] decodeImage(@RequestParam("file") MultipartFile file) throws Exception {
File file1 = addProperties(file);
return FileUtils.readFileToByteArray(file1);
}
js代码
$scope.extractImage = function (sourceFile) {
Upload.upload({
url: '/image/decode',
objectKey: '',
data: {
file: sourceFile
}
}).then(function (response) {
console.log('Success ' +'Response: ' + response);
$scope.image = response.data;
}, function (response) {
console.log('Error status: ' + response);
});
};
HTML代码
<img class="thumb image-properties" ng-if="image" ng-src="{{image}}" />
【问题讨论】:
-
尝试将其转换为数据uri:
data:image/png;base64,<data converted to Base64> -
实际上更好的副本是:stackoverflow.com/questions/14979791/…
-
我在答案中添加了
<img ng-src="data:image/JPEG;base64,{{image}}">,但未显示静止图像,将$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|ftp|blob):|data:image\//);放在哪里?
标签: javascript java image angular response