我正在尝试从 s3 下载文件,后端由 NodeJS 处理,前端是 ui5。nodejs 的响应是s3.getObject(downloadParams).createReadStream().pipe(res)
。
获取图像的 AJAX 代码。
jQuery.ajax({
url: "image/key",
type: params.method,
success: function (data, textStatus, request) {
var blob = new Blob([data],{ type: 'image/png' });
var fileName = params.fileName;
var url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
},
error: function (response) {
MessageBox.error("Something went wrong please try again");
}
})
我得到的“数据”success: function (data, textStatus, request)
是一个字符串,比如�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000@\u0000\u0000\u0000@\b\u0002\u0000\u0000\u0000%\u000b�\u0000\u0000\u0000\
......我无法正确解码这个字符串。我怎样才能下载这个文件?