我正在编写一个前端javascript应用程序,我需要在屏幕上发送用户上传到java后端的图像。
最有效的发送方式是什么?我应该得到图像base64还是应该将像素存储在矩阵中并发送它们
编辑:我不是在寻找代码解决方案只是建议采取的方法
答案 0 :(得分:0)
我正在使用base64。在应用程序中缓存更容易。
var image64 = null;
var xhr = $.ajax({
type: "post",
url: '/image_url/',
data: {},
success: function (o) {
if (o) {
if (!o.err) {
image64 = o;
$('img').attr('src', 'data:image/png;base64,' + image64);
} else {
if (o.err && o.err.code === 'session_destroy') {
sessionDestroyed()
} else if (o.err){
alertError(o.err);
}
}
}
},
error: function (xhr) {
if (xhr.responseText != '') {
alert(xhr.responseText);
}
}
});