
我的attachment.rb的代码是:
class Attachment < ActiveRecord::Base belongs_to :article has_attached_file :url,:s3_protocol => :https,styles: { medium: "300x300>",thumb: "100x100>",big: "1200x1200>",normal: "600x600>" } valIDates_attachment_content_type :url,content_type: /\aimage|\AvIDeo\/.*\Z/ valIDates_attachment :url,content_type: { content_type: ["image/jpeg","image/gif","image/png","vIDeo/mp4"] }end 但事实并非如此,它并没有在S3上存储视频.我在终端上得到以下内容
Command :: file -b --mime '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/f3e2afc957bb9fb2aa3e77e69359c48920160131-13311-pyeez1.mp4'Command :: IDentify -format '%wx%h,%[exif:orIEntation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null[paperclip] An error was received while processing: #<Paperclip::Errors::NotIDentifIEdByImageMagickerror: Paperclip::Errors::NotIDentifIEdByImageMagickerror>Command :: IDentify -format '%wx%h,%[exif:orIEntation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null[paperclip] An error was received while processing: #<Paperclip::Errors::NotIDentifIEdByImageMagickerror: Paperclip::Errors::NotIDentifIEdByImageMagickerror>Command :: file -b --mime '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/f3e2afc957bb9fb2aa3e77e69359c48920160131-13311-kvb5nr.mp4'
第二个问题是因为我正在使用AngularJs作为前端,我可以利用HTML< vIDeo>标记以将视频呈现给用户?
解决方法 看起来问题是ImageMagick正在尝试 transcode视频,但它不能.在Paperclip中处理视频转码的方法是使用paperclip-av-transcoder gem(以前的paperclip-ffmpeg).我只对后者有经验:
#app/models/attachment.rbclass Attachment < ActiveRecord::Base has_attached_file :url,styles: lambda { |a| a.instance.is_image? ? medium: "300x300>",normal: "600x600>" } : {:thumb => { :geometry => "100x100#",:format => 'jpg',:time => 10},:medium => { :geometry => "300x300#",:time => 10}}},processors: [:transcoder] valIDates_attachment :url,content_type: ['vIDeo/mp4'],message: "Sorry,right Now we only support MP4 vIDeo",if: :is_vIDeo? valIDates_attachment :url,content_type: ['image/png','image/jpeg','image/jpg','image/gif'],message: "Different error message",if: :is_image? private def is_vIDeo? url.instance.attachment_content_type =~ %r(vIDeo) end def is_image? url.instance.attachment_content_type =~ %r(image) endend Our old code& @L_301_4@
总结以上是内存溢出为你收集整理的ruby-on-rails – 图像和视频的回形针全部内容,希望文章能够帮你解决ruby-on-rails – 图像和视频的回形针所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)