我的 React 组件中有这个,我将在其中单击 adownload
下载文件:
<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 标头设置为以下内容:
Content-Disposition: attachment; filename="filename.[yourextention]"
如果这是 PDF,浏览器扩展程序想要阅读而不是下载,这是很常见的!
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句