Skip to content

Instantly share code, notes, and snippets.

@neovintage
Created December 7, 2011 21:19
Show Gist options
  • Save neovintage/1444714 to your computer and use it in GitHub Desktop.
Save neovintage/1444714 to your computer and use it in GitHub Desktop.
plupload - mongodb - carrierwave
class Asset
include Mongoid::Document
include Mongoid::Timestamps
field :name
field :type
field :extension
field :uploaded_by
mount_uploader :file, AssetUploader
end
def create
@image = Asset.new(:name => params[:name])
@image.file = params[:file]
@image.save!
render :nothing => true
end
<%= javascript_include_tag "path to your javascript dir/plupload.full.min.js" %>
<script type="text/javascript">
$(function(){
var uploader = new plupload.Uploader({
runtimes : "gears,silverlight,flash,html5",
browse_button : 'pickfiles',
container : "upcontainer",
max_file_size : '10mb',
url : "/admin/assets",
flash_swf_url: "/javascripts/plupload.flash.swf",
silverlight_xap_url: "/javascripts/plupload.silverlight.xap",
multipart: true,
multipart_params: {
"authenticity_token" : '<%= form_authenticity_token %>'
}
});
uploader.bind('Init', function(up, params) {
$('#filelist').html("<div>Current runtime: " + params.runtime + "</div>");
});
uploader.bind('FilesAdded', function(up, files) {
$.each(files, function(i, file) {
$('#filelist').append(
'<div id="' + file.id + '">' +
'File: ' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +'</div>'
);
});
});
uploader.bind('UploadProgress', function(up, file) {
$('#' + file.id + " b").html(file.percent + "%");
});
$('#uploadfiles').click(function(e) {
uploader.start();
e.preventDefault();
});
uploader.init();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment