ruby on rails - How to allow Binary File download using GRAPE API -


i want allow downloading binary file (.p12 file) using ruby's grape api. trying.

get '/download_file'   pkcs12 = generate_pkcsfile    content_type('application/octet-stream')   body(pkcs12.der) end 

the equivalent code using actioncontroller is

begin   pkcs12 = generate_pkcsfile   send_data(pkcs12.der,             :filename => 'filename.p12') end 

the problem file downloaded using api seems text file '\ufffd' prefix embedded every character, whereas file downloaded using browser seems binary file. how use grape api framework allow downloading same file downloaded via actioncontroller's send_data

there issues #412 , #418 have been reported grape github page. related return binary file , override content type.

to return binary format so:

get '/download_file'     content_type "application/octet-stream"     header['content-disposition'] = "attachment; filename=yourfilename"     env['api.format'] = :binary     file.open(your_file_path).read end 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -