You want to use data-urls. here's an example of how I've used it:
<div>
<%= f.file_field :image, :id => "image" %>
<output id="image_preview_output">
</output>
</div>
<script>
$(document).ready(function() {
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
} else {
alert('The File APIs are not fully supported in this browser.');
}
});
$('#image').change(function previewImage(evnt) {
var file = evnt.target.files[0];
// Only process image files.
if (!project_featured_image.type.match('image.*')) {
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var span = document.createElement('span');
span.innerHTML = ['<img id="image_preview" src="', e.target.result, '" title="', escape(theFile.name), '"/>'].join('');
$('#image_preview_output').html(span);
};
})(file);
// Read in the image file as a data URL.
reader.readAsDataURL(file);
}
});
</script>