我的 React 组件中有这个,我将在其中单击 download
来下载文件:
<a
key={file.attachmentId} className="item uploaded"
href={Pathes.Attachments.getById(file.attachmentId)}
target="_blank"
download
>
Download
</a>
我的文件路径:
static Attachments = class {
static base = baseApi('attachments/download')
static getById = (attachmentsId: any) => baseApi(`attachments/download/${attachmentsId}`)
}
结果,文件在浏览器中打开但未下载。
最佳答案
您可以尝试将 HTTP header 设置为以下内容:
Content-Disposition: attachment; filename="filename.[yourextention]"
如果这是 PDF,浏览器扩展想要阅读而不是下载,这是很常见的!
希望这有帮助。
关于javascript - 下载 anchor 标记在浏览器中打开文件,但不在 React 组件中下载它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51324276/