How can I send binary data from Sinatra?

后端 未结 4 1517
深忆病人
深忆病人 2021-02-12 17:18

I want to send binary data from a Sinatra application so that the user can download it as a file.

I tried using send_databut it gives me an undefined

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-12 18:04

    I did it like this:

    get '/download/:id' do
      project = JSON.parse(Redis.new.hget('active_projects', params[:id]))
      response.headers['content_type'] = "application/octet-stream"
      attachment(project.name+'.tga')
      response.write(project.image)
    end
    

提交回复
热议问题