当用户下载文件时在另一台服务器上重命名文件

发布于 2024-07-13 17:26:52 字数 253 浏览 3 评论 0原文

我允许用户只需向他们提供链接即可从另一台服务器下载文件。

但是,当用户尝试下载文件时,文件始终命名为“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呆头 2024-07-20 17:26:52

不,这是不可能的,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.

原来是傀儡 2024-07-20 17:26:52

我相当确定 Javascript 不会让你这样做。

更好的选择可能是发送 HTTP Content-Disposition 标头,如下所示:

Content-Disposition,attachment; filename=foobar.zip

其中 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:

Content-Disposition,attachment; filename=foobar.zip

where foobar.zip is the name you wish the file to be called.

倾`听者〃 2024-07-20 17:26:52

这不可能。 下载文件时显示特定文件名的唯一方法是控制远程服务器并将其设置为设置特定的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文