현재 데이터베이스 및 S3을 사용하여 다양한 파일을 저장할 수 있습니다. 그러나 이러한 파일을 잘 표시 할 수는 없습니다.ruby on rails : 파일 업로드 및 파일 표시에 관하여
아래 코드는 showviewfile 코드입니다. 여기에 내가하고 싶은 두 가지가 있습니다.
<div class="listing_content">
<% if @listing.file_content_type == 'video/mp4' then %>
<%= video_tag @listing.file, :controls => true, width: "640", height: "360" %>
<% elsif @listing.file_content_type == "image/jpg" || "image/jpeg" || "image/png" || "image/gif" then %>
<%= image_tag @listing.file, :width => 640, :height => 340 %>
<% elsif @listing.file_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' then %>
<%= audio_tag @listing.file, :controls => true %>
<% else %>
<%= image_tag @listing.file %>
<% end %>
</div>
첫 번째는 각 형식에 대해 저장된 파일을 표시하는 것입니다. 둘째, 아래 이미지를 참조하십시오. 오디오 파일이 제대로 표시되지 않습니다.
그래서, 나는이 문제를 해결하고 싶습니다,하지만 난 그것을 해결하는 방법을 모르겠어요. 어떻게 해결할 수 있을까요?
모델 파일
validates_attachment :file, content_type: { 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', 'video/mp4', 'text/plain', 'application/msword', 'application/vnd.ms-powerpoint', 'application/pdf', "image/jpg", "image/jpeg", "image/png", "image/gif"] }
말해주십시오!
파일을 제대로 업로드하고 있는지 확인할 수 있습니까? 또한 파일 업로드에 어떤 보석을 사용하고 있습니까? – Maru
[mcve]를 제공 할 수 있습니까? 나는 당신이 어떤 파일을 업로드하는지, 그것이 어떻게 업로드되었는지, 어떻게 처리되는지,'file_content_type'의 값이 무엇인지 알지 못합니다. –