2017-11-28 5 views
1

현재 데이터베이스 및 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> 

첫 번째는 각 형식에 대해 저장된 파일을 표시하는 것입니다. 둘째, 아래 이미지를 참조하십시오. 오디오 파일이 제대로 표시되지 않습니다.

enter image description here

그래서, 나는이 문제를 해결하고 싶습니다,하지만 난 그것을 해결하는 방법을 모르겠어요. 어떻게 해결할 수 있을까요?

모델 파일

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"] } 

말해주십시오!

+1

파일을 제대로 업로드하고 있는지 확인할 수 있습니까? 또한 파일 업로드에 어떤 보석을 사용하고 있습니까? – Maru

+1

[mcve]를 제공 할 수 있습니까? 나는 당신이 어떤 파일을 업로드하는지, 그것이 어떻게 업로드되었는지, 어떻게 처리되는지,'file_content_type'의 값이 무엇인지 알지 못합니다. –

답변

0

나는 당신의 조건에 적어도 문제를 참조하십시오 알파 || 알파가 "true-ish"이면 베타는 베타로 평가됩니다. 그것은 당신에게 이미지를주는 대신에 적절하게 오디오 파일을 재생 왜

['audio/mpeg', 'audio/x-mpeg', 
'audio/mp3', 'audio/x-mp3'].include?(@listing.file_content_type) 

이처럼 뭔가에 조건문을 변경

봅니다 아마. 파일이 mp4, gif 또는 mpegaudio가 아니면 이미지를 얻을 수 있습니다.

0

어떤 라이브러리를 업로드에 사용합니까?

carrierwave/paperclip이 매개 변수로 @ listing.file.url을 대신 제공하려고 시도했을 수 있습니다.