How to Allow Binary File Download Using Grape API

How can I send binary data from Sinatra?

you can just return binary data:

get '/binary' do
content_type 'application/octet-stream'
"\x01\x02\x03"
end

Groovy - Grab - download failed

It looks like your Grape settings are set only to look in your local .m2 directory for the library. Check your grapeConfig.xml configuration file. (If you don't have one, you can create it--it should go in the same directory where your groovysh.history and grapes cache directory are created by Groovy.) You can copy the example file shown on the Groovy Grape reference page.

If that doesn't help, I would try deleting your grapes cache directory and try it again.

download csv file to computer

You need to set headers to indicate what the browser should be doing with the resulting file.

send_data file, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment;data=#{csv_file}.csv"

However, it would have to be written first, to the server, and then downloaded. You might find this answer helpful: Ruby 1.9.2 export a CSV string without generating a file



Related Topics



Leave a reply



Submit