我的回形针(带有S3)在我的应用程序中工作,用于音频文件。模型定义连接S3和回形针。没有视图的回形针
# attachments
has_attached_file :audio, storage: :s3, s3_credentials: Proc.new{|a| a.instance.s3_credentials}
validates_attachment_content_type :audio, :content_type => [ 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'audio/x-mp3', 'audio/mpeg3', 'audio/x-mpeg3', 'audio/mpg', 'audio/x-mpg', 'audio/x-mpegaudio' ]
我可以通过轨道simple_form上传的文件,使用此代码:
<%= simple_form_for(@sentence) do |f| %>
<%= f.error_notification %>
.
<%= f.input :audio, as: :file %>
.
<% end %>
我也想创建使用背景(Resque)处理音频。此代码从Web API检索音频流并尝试将其保存到现有的模型实例。这是行不通的。
sentences.each do |sentence|
sentence.audio = get_audio(sentence.sentence)
sentence.save
end
回形针似乎不知道如何处理音频流。
failed: #<Paperclip::AdapterRegistry::NoHandlerError: No handler found for "\xFF\xF3\xC8\xC4\x00\x00\x00\x03H\x00\x00\x00\x00LAME3.99.5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
** **进展
我取得了一些进展:写的音频流的将它视为......但现在回形针抱怨编码
def get_audio_tempfile(target)
audio = translator.speak "#{target}", :language => "#{@language_cd}", :format => 'audio/mp3', :options => 'MaxQuality'
tempfile = Tempfile.new("target_temp.mp3")
tempfile.binmode
tempfile.write(audio)
tempfile.close
tempfile.open
tempfile
end
错误:
[paperclip] Content Type Spoof: Filename target_temp.mp320160226-32064- r391y9 (audio/mpeg from Headers, [] from Extension), content type discovered from file command: audio/mpeg. See documentation to allow this combination.