音频的内容不是他们所报道的内容 - Paperclip

问题描述 投票:2回答:1

这里是Ruby的初学者!我正在尝试在ruby上创建一个Soundcloud克隆。当我尝试上传音频文件时,我收到错误: 1错误禁止保存此歌曲: 音频的内容不是他们报道的内容

控制器:song.rb

class Song < ActiveRecord::Base
belongs_to :user
has_attached_file :audio,
                  :url => "/assets/:class/:id/:attachment/:basename.:extension",
                  :path => ":rails_root/public/assets/:class/:id/:attachment/:basename.:extension"
validates_attachment :audio,
                     :content_type => { :content_type => ["audio/mpeg", "audio/mp3"] },
                     :file_name => { :matches => [/mp3\Z/] }

_form.html.erb

<%= form_for(@song) do |f| %>
<% if @song.errors.any? %>
<div id="error_explanation">
  <h2><%= pluralize(@song.errors.count, "error") %> prohibited this song from being saved:</h2>
  <ul>
  <% @song.errors.full_messages.each do |message| %>
    <li><%= message %></li>
  <% end %>
  </ul>
</div>
<% end %>
<div class="field">
 <%= f.label :audio %><br>
 <%= f.file_field :audio%>
</div>  
<div class="field">
 <%= f.label :title %><br>
 <%= f.text_field :title %>
</div>
<div class="field">
 <%= f.label :description %><br>
 <%= f.text_field :description %>
</div>
<div class="actions">
 <%= f.submit %>
</div>
<% end %>

show.html.erb

<p id="notice"><%= notice %></p>
<p>
<strong>Audio:</strong>
<%= @song.audio.url %>
</p>
<p>
<strong>Title:</strong>
<%= @song.title %>
</p>
<%= link_to 'Edit', edit_song_path(@song) %> |
<%= link_to 'Back', songs_path %>
html ruby-on-rails ruby gem paperclip
1个回答
0
投票

根据我对这个问题的体验,mp3元数据中的图像数据(即 - 专辑封面)是关键因素。图像数据触发内容类型欺骗机制,记录将无法通过验证。为了删除图像元数据,我用Audacity打开了mp3,并将其导出到一个新文件,该文件不包含图像元数据,因为Audacity似乎不会自动包含这个元素。

© www.soinside.com 2019 - 2024. All rights reserved.