开发者

Writing out a custom file as a response from a rails controller action

开发者 https://www.devze.com 2023-01-06 04:24 出处:网络
So I want to dynamically generate a MIDI file on a web request.Coming from the Java world, I expected something to the tune of

So I want to dynamically generate a MIDI file on a web request.Coming from the Java world, I expected something to the tune of

class MidisController < ApplicationController
  before_filter :set_content_type    
  def set_content_type
    @headers["Content-Type"] = "audio/midi; charset=utf-8"
  end

  def show
    midi_data = get_midi_data 
    response.write(midi_data)
  end

But the API says, stay away from the response object. 开发者_高级运维Any ideas ?


Look at the Rails docs for send_file or send_data. It handles all of the header requirements for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消