문제

I'm building a document service on sinatra. In the response, I want to send the JSON data and an attachment. How can I do this in sinatra?

도움이 되었습니까?

해결책

The best way to handle this is to provide just two routes.

Something like this:

get "/json" do
    return json
end

get "/file/:name" do |filename|
    send_file file.filePath, :filename => file.fileName, :disposition => 'attachment'
end

And in your json respons you include the path to your file.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top