-
-
Save alispat/1943421 to your computer and use it in GitHub Desktop.
plupload - mongodb - carrierwave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Asset | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
field :name | |
field :type | |
field :extension | |
field :uploaded_by | |
mount_uploader :file, AssetUploader | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@image = Asset.new(:name => params[:name]) | |
@image.file = params[:file] | |
@image.save! | |
render :nothing => true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= javascript_include_tag "path to your javascript dir/plupload.full.min.js" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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