[英]Change Content-Disposition filename with userscript from a Post
I would like to change the file name of a downloaded file from Submit that uses Content-Disposition: attachment; filename=Reports.csv
我想从使用
Content-Disposition: attachment; filename=Reports.csv
Submit更改已下载文件的文件名Content-Disposition: attachment; filename=Reports.csv
Content-Disposition: attachment; filename=Reports.csv
I would like to Download that file with a preset file name Content-Disposition: attachment; filename=AnyFileName.csv
我想下载一个带有预设文件名
Content-Disposition: attachment; filename=AnyFileName.csv
文件Content-Disposition: attachment; filename=AnyFileName.csv
Content-Disposition: attachment; filename=AnyFileName.csv
I would need it to be userscript friendly 我需要它是用户友好的
The Download is Post and the content it returns is Content-Type: application/octet-stream; charset=UTF-8
Download is Post,下载的内容为
Content-Type: application/octet-stream; charset=UTF-8
Content-Type: application/octet-stream; charset=UTF-8
I need it to change the filename of the download file 我需要它来更改下载文件的文件名
That's not gonna be easy at all. 那根本不容易。 To do this you will have to:
为此,您将必须:
XMLHttpRequest
or fetch
API XMLHttpRequest
或fetch
API正确发送表单 Blob
. Blob
。 You need to use responseType
to request Blob
responseType
来请求Blob
URL.createObjectURL
to create downloadable data URL URL.createObjectURL
创建可下载的数据URL Create link to allow download: 创建链接以允许下载:
<a href="${YOUR_DATA_URL}" download="AnyFileName.csv">Download</a>
URL.revokeObjectURL
URL.revokeObjectURL
释放内存。 I'm sory, it's probably much more work than you expected. 我很抱歉,这可能比您预期的要多得多。 Good luck.
祝好运。 You may alternatively consider some add-on or program that tampers with the HTML headers for that particular site.
您也可以考虑使用某些插件或程序来篡改该特定网站的HTML标头。
It would be much easier if you could use the download
attribute on <form>
, but that's not possible . 如果可以在
<form>
上使用download
属性,则会容易得多, 但这是不可能的 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.