Ruby Sinatra 附件

发布于 2024-11-16 03:11:17 字数 210 浏览 9 评论 0原文

我有一个 sinatra 应用程序,当用户单击文件时,它会向用户发送一个文件,我不想提供扩展名,但 Sinatra 或浏览器给它“test.html”,

attachment("test")
response.write("write test data")

我怎样才能给出 test 的文件名给用户,而不将其重命名为 test.html

I have a sinatra application that sends a file to the user when they click a file, I don't want to give an extension, but Sinatra or the browser is giving it "test.html"

attachment("test")
response.write("write test data")

how can I give the file name of test to the user without it getting renamed to test.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

南笙 2024-11-23 03:11:17

根据 Sinatra 传递给浏览器的 MIME 类型,这可能是浏览器正在执行的操作。

如今,扩展在 Windows、Mac OS 和 Linux 操作系统上非常重要,因此该价值对用户及其计算机的操作系统很有帮助。也许您可以通过提供有关所发送内容的实际类型的提示来改进事情。

Sinatra 的“MIME 类型”文档说道:

当使用 send_file 或静态文件时,您可能有 Sinatra 无法理解的 mime 类型。使用 mime_type 通过文件扩展名注册它们:

configure do
  mime_type :foo, 'text/foo'
end

您还可以将其与 content_type 帮助器一起使用:

get '/' do
  content_type :foo
  "foo foo foo"
end

It might be something the browser is doing, based on the MIME type being passed to it by Sinatra.

Extensions are significant on Windows, Mac OS and Linux OSes these days, so that value is helpful for the user and their machine's OS. Maybe you can improve things by providing a hint about the actual type of content being sent.

Sinatra's "MIME Types" documentation says:

When using send_file or static files you may have mime types Sinatra doesn’t understand. Use mime_type to register them by file extension:

configure do
  mime_type :foo, 'text/foo'
end

You can also use it with the content_type helper:

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