go-http-file-server icon indicating copy to clipboard operation
go-http-file-server copied to clipboard

下载文件或下载压缩包时,如何通过修改content-disposition中 filename 值的方式自定义文件名?

Open dengwenwen45 opened this issue 7 months ago • 2 comments

当前下载文件URL:http://localhost/dir/file.txt?download

使用以上URL下载文件时,默认文件名是 file.txt,因为服务端content-disposition = attachment; filename=file.txt; filename*=UTF-8''file.txt

如何通过修改URL链接参数的方式,修改服务端content-disposition中的filename值呢? 比如加入参数filename:http://localhost/dir/file.txt?download&filename=new_file_name.txt 让服务端content-disposition 值变成 attachment; filename=new_file_name.txt; filename*=UTF-8''new_file_name.txt

同理下载压缩包 http://localhost/tmp?zip&filename=new_file_name.zip 让服务端content-disposition 值变成 attachment; filename=new_file_name.zip; filename*=UTF-8''new_file_name.zip

可以实现么?

dengwenwen45 avatar Jun 12 '25 09:06 dengwenwen45

目前改成download[=filename]zip[=filename]的形式,代码在unstable分支,之后会合并到主分支。

marjune163 avatar Jun 15 '25 04:06 marjune163

已发布到1.21.1

marjune163 avatar Sep 27 '25 09:09 marjune163