Reputation: 33
I can't save audio file, so can you tell me how to save about audio file . I use gem paperclip !
log is Command :: file -b --mime '/var/folders/1z/psyvq9q911b7hclx5xw03dk40000gn/T/4266fc074db087b967597da8e4d2d11020171116-3739-1bal5v0.mp3' [paperclip] Content Type Spoof: Filename as333auda.mp3 (audio/mp3 from Headers, ["audio/mpeg"] from Extension), content type discovered from file command: video/mp4. See documentation to allow this combination. (0.1ms) begin transaction Command :: file -b --mime '/var/folders/1z/psyvq9q911b7hclx5xw03dk40000gn/T/4266fc074db087b967597da8e4d2d11020171116-3739-wh10af.mp3' [paperclip] Content Type Spoof: Filename as333auda.mp3 (audio/mp3 from Headers, ["audio/mpeg"] from Extension), content type discovered from file command: video/mp4. See documentation to allow this combination. (0.2ms) rollback transaction Redirected to http://localhost:3000/listings/new Completed 302 Found in 128ms (ActiveRecord: 3.0ms)
show you model listing.rb
class Listing < ApplicationRecord
belongs_to :user
has_many :photos
has_many :likes
has_many :customers
has_many :reviews
validates :listing_title, presence: true
has_attached_file :file, :storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml"
validates_attachment :file, content_type: { content_type: ['file/mp3'] }
end
show you view new.html.erb
<%= form_for @listing do |f| %>
<div class="row">
<div class="col-md-12 select">
<div class="form-group">
<label>タイトル</label>
<%= f.text_field :listing_title, autofocus: true, :placeholder => "タイトル", :class => 'form-control', required: "true" %>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-12 select">
<div class="form-group">
<label>ファイル</label>
<%= f.file_field :file, :class => 'form-control' %>
</div>
</div>
</div>
<br>
<div class="actions">
<%= f.submit "Save", class: "btn btn-danger" %>
</div>
<% end %>
Controller is nothing problem! I set params! What should I need I success to save audio file? Please tell me!
Upvotes: 0
Views: 520
Reputation: 1173
Try with:
{ content_type: ['audio/mp3'] }
If this still doesn't work you can try this:
{ 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'] }
Upvotes: 1
Reputation: 2384
MP3 audio files has mime typed "audio/mpeg"
Change your content type to "audio/mpeg"
Upvotes: 0