File io Sinatra中的多部分响应

File io Sinatra中的多部分响应,file-io,sinatra,File Io,Sinatra,我正在sinatra上建立一个文档服务。在响应中,我想发送JSON数据和附件。在西纳特拉我该怎么做?处理这个问题的最好方法是只提供两条路线 大概是这样的: get "/json" do return json end get "/file/:name" do |filename| send_file file.filePath, :filename => file.fileName, :disposition => 'attachment' end 在json响应

我正在sinatra上建立一个文档服务。在响应中,我想发送JSON数据和附件。在西纳特拉我该怎么做?

处理这个问题的最好方法是只提供两条路线

大概是这样的:

get "/json" do
    return json
end

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

在json响应中包含文件路径。

在json中包含文件字节字符串如何?或者更简单,只需对json文件使用2个请求,对附件使用1个请求,或者您合并这些文件的原因是什么?是的,这很有意义。我已经改变了API设计,在两个不同的调用中处理这些问题。我将其添加为答案,您可以接受它。