繁体   English   中英

在PaperClip中上传没有表单或数据库的图像

[英]Uploading an image without a form or database in PaperClip

我是Ruby的新手。

我有一个DIV,其中有一个默认图像。

我要在点击该图片或div时上传另一张图片。 我不想将此图像保存到数据库。 我也不想像大多数回形针教程所说的那样使用表单(如果有没有表单的方法)。

您想使用data-urls 这是我如何使用它的一个示例:

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM