Yes, the input [type = file] is read-only for security reasons. I just solved a similar problem by converting the input [type = file] to the input [type = hidden] and setting the value as base64 encoded URI.
(By the way, this automatically works with Paperclip https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/io_adapters/data_uri_adapter.rb )
Here is my jquery code:
$(function() { function renderPreviewImageFromFile(e,file) { file = file || $(this).prop('files')[0]; if(file) { var img = $(this).parents('li').find('img.preview'); var reader = new FileReader(); reader.onload = function(e) { img.attr('src', e.target.result); } reader.readAsDataURL(file); return img.attr('src'); } } $("ul.images-list") .on('change','input.file',renderPreviewImageFromFile); jQuery.event.props.push("dataTransfer"); $('.file-drop') .on('dragover dragenter', function(e) { $(this).addClass('hover'); e.preventDefault(); e.stopPropagation(); }).on('dragleave dragexit', function(e) { $(this).removeClass('hover'); e.preventDefault(); e.stopPropagation(); }).on('drop', function(e) { $(this).removeClass('hover').find('span').remove(); e.preventDefault(); e.stopPropagation();
source share