当用户下载文件时在另一台服务器上重命名文件
我允许用户只需向他们提供链接即可从另一台服务器下载文件。
但是,当用户尝试下载文件时,文件始终命名为“file.zip”。 我希望我可以使用 JavaScript 将文件重命名为更合适的名称。
我怎样才能做到这一点? 这可能吗?
将不胜感激任何帮助。
谢谢大家
更新
将该文件保存到我的服务器并在我这样做时让用户下载它怎么样? 用户可以开始下载未完全下载的文件吗?
I am allowing users to download a file from another server just by giving them the link.
However, the files are always named "file.zip" when users try to download it. I was hoping I could use maybe JavaScript to rename the file for them to something more appropriate.
How can I do this? Is this possible?
Would appreciate any help.
Thanks all
UPDATE
How about saving that file to my server and as I do this, let the users download it? Can users start downloading an un-fully downloaded file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,这是不可能的,file.zip 将位于服务器发送的 Content-Disposition 标头中,您无法在 Javascript 中执行任何操作来拦截和修改它。
No its not possible, the file.zip will be in the Content-Disposition header sent by the server, there is nothing you can do in Javascript to intercept and modify it.
我相当确定 Javascript 不会让你这样做。
更好的选择可能是发送 HTTP Content-Disposition 标头,如下所示:
其中 foobar.zip 是您希望调用该文件的名称。
I'm fairly sure Javascript won't let you do this.
A better option might be to send a HTTP Content-Disposition header, like so:
where foobar.zip is the name you wish the file to be called.
这不可能。 下载文件时显示特定文件名的唯一方法是控制远程服务器并将其设置为设置特定的 http 标头。
This is not possible. The only way to show specific file names when downloading files is controlling the remote server and setting it to set a specific http header.