开发者

How can I answer a POST request with a static file in Sinatra?

开发者 https://www.devze.com 2022-12-13 13:03 出处:网络
In Sinatra, if you have a \"GET /images/photo1.jpg\" request... you can save a lot of time by making a \"public\" directory. Any route not found is assumed t开发者_运维知识库o be inside your \"public\

In Sinatra, if you have a "GET /images/photo1.jpg" request... you can save a lot of time by making a "public" directory. Any route not found is assumed t开发者_运维知识库o be inside your "public" directory.

However this seems to work just for GET requests. Is there a way to do something similar for POST requests?

Either:

  • Turning on some static method?
  • Maybe forging an inner request?
  • Duplicating functionality?

Any ideas? Is this even a bug?

PS: I know it's not RESTful to ask for files in a POST request, unfortunately Facebook works that way.


That sounds like something you should attack with rack middleware.


The send_file helper is what you want.

send_file "/your/file.txt", {:filename=>"foobar.dat"}
0

精彩评论

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