开发者

Ruby Sinatra attachment

I have a sinatra application that sends a file to the user when they click a file, I don't 开发者_Python百科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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜