Swfupload_fu是rails一个插件,可以在rails中方便使用Swfupload和Attachment_Fu 进行上传,
需要用到mime-types和Attachment_Fu
1.安装
script/plugin install git://github.com/alex3t/swfupload_fu.git
2.在你要使用的视图中添加SWFUploadFu helper
<head>
<title>...</title>
<%=swfupload_head %>
</head>
然后,在你要用的地方,比如我的
<%=swfupload :controller=>'photos',:action=>'upload'%>
3.Attachment_Fu 的配置
require 'mime/types'
class Photo < ActiveRecord::Base
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 2.megabytes,
:resize_to => '640x360>',
:thumbnails => { :thumb => '140x105>' }
def swf_uploaded_data=(data)
data.content_type = MIME::Types.type_for(data.original_filename)
self.uploaded_data = data
end
validates_as_attachment
end
最后在你要用的控制器中
例如我的photos_controller中加入
def upload
@file = Photo.new :swf_uploaded_data => params[:Filedata]
@file.save!
render :text => @photo.public_filename(:thumb)
rescue
render :text => "Error"
end
搞定
相关地址:
swfupload: http://swfupload.org/
swfupload_fu: http://github.com/alex3t/swfupload_fu
attachment_fu: http://github.com/technoweenie/attachment_fu