How to allow Binary File download using GRAPE API

后端 未结 2 833
抹茶落季
抹茶落季 2021-02-04 15:21

I want to allow downloading a binary file (.p12 file) using ruby\'s Grape API. This is what I am trying.

get \'/download_file\' do
  pkcs12 = generate_pkcsfile 
         


        
2条回答
  •  北海茫月
    2021-02-04 15:33

    There are issues #412 and #418 have been reported to grape github page. Which are related to return a binary file and override content type.

    To return binary format like so:

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

提交回复
热议问题