jQuery File Upload preview image

空扰寡人 提交于 2019-11-28 18:01:11

I don't think that the Jquery File Upload plugin provides preview functionality.

But you can easily implement it into the plugin's add option:

add: function (e, data) {
    if (data.files && data.files[0]) {
        var reader = new FileReader();
        reader.onload = function(e) {
            $('#target').attr('src', e.target.result);
        }
        reader.readAsDataURL(data.files[0]);
        ...
        data.submit();
    }
}

Live exemple without BlueImp plugin.

The plugin does support image previews though I'm trying to figure out how to resize it to a higher resolution. You can access the preview by doing something like this:

$('.fileupload-field')
  .fileupload({
     disableImageResize: false, 
     previewMaxWidth: 320, 
     previewMaxHeight: 320
  })
  .bind('fileuploadprocessalways', function(e, data)
  {
      var canvas = data.files[0].preview;
      var dataURL = canvas.toDataURL();
      $("#some-image").css("background-image", 'url(' + dataURL +')');

  })

" File reader API is not supported in IE-9, so to preview the image, do the following steps:

1> send the image to the server using ajax>2>Get the image source from the server after uploading as response 3> by using the image source, append it to the preview image tag "

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!