CSY247
CSY247
标签
标签tag ∈ [1, N] · one; one ∈ [0, 5] · tag
独立
独立独立于本网站的应用、网页、服务、插件等。
通过 a 标签下载文件时通常可用以下代码:
<a href="http://127.0.0.1:8000/files/temp.pdf" download="参考文件.pdf">文件下载</a>
如果说页面地址也是 http://127.0.0.1:8000
开始的话是没有问题的。但是如果是其他域,download
属性将会失效。
server {
listen 80; # 监听端口
server_name mydomain.com; # 你的域名
# 配置本地 HTML 文件服务
location / {
root /usr/share/nginx/html; # HTML 文件的根目录
index index.html; # 默认索引文件
}
# 配置外部 HTTP 服务的代理
location /file {
proxy_pass http://external-service.com/path/to/file; # 目标服务地址
proxy_set_header Host $host; # 传递原始 Host 头
proxy_set_header X-Real-IP $remote_addr; # 传递客户端真实 IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 传递客户端真实 IP
proxy_set_header X-Forwarded-Proto $scheme; # 传递原始协议
}
}
function downloadFile(url, filename) {
fetch(url) // 获取文件
.then((response) => response.blob())
.then((blob) => {
const objectUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = objectUrl;
a.download = filename; // 设置自定义文件名
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(objectUrl); // 释放对象 URL
});
}
✨相关推荐✨