如何下载从我的服务器返回的缓冲区?
How do I download a Buffer that is returned from my server?
我有一个缓冲区,其中包含我未能成功下载的 PDF。每次我尝试打开 PDF 时,它都无法打开。这是我用来下载文件的代码:
const content = new Blob(attach.content.data, { type: attach.contentType });
const encodedUri = window.URL.createObjectURL(content);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", attach.filename);
link.click();
附加对象如下所示:
这是 Blob 的样子:
停一停!!!1
问题是我没有将 Node.js 缓冲区转换为浏览器可读的 ArrayBuffer:
const data = Uint8Array.from(attach.content.data);
const content = new Blob([data.buffer], { type: attach.contentType });
const encodedUri = window.URL.createObjectURL(content);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", attach.filename);
link.click();
我有一个缓冲区,其中包含我未能成功下载的 PDF。每次我尝试打开 PDF 时,它都无法打开。这是我用来下载文件的代码:
const content = new Blob(attach.content.data, { type: attach.contentType });
const encodedUri = window.URL.createObjectURL(content);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", attach.filename);
link.click();
附加对象如下所示:
这是 Blob 的样子:
停一停!!!1
问题是我没有将 Node.js 缓冲区转换为浏览器可读的 ArrayBuffer:
const data = Uint8Array.from(attach.content.data);
const content = new Blob([data.buffer], { type: attach.contentType });
const encodedUri = window.URL.createObjectURL(content);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", attach.filename);
link.click();