I'm having hard time figuring out how to preview the file thumbnail image something like that before uploading it. So when i browse a file using file chooser and select the file i wanted to upload it will display its corresponding preview, like .txt, .csv, .xls, or xlsx, etc. Is there a way to achieve this in any ways? Simple ways or complex ways may work. How do i achieve something like this one?

在上传之前,我很难弄清楚如何预览文件的缩略图。因此,当我使用file chooser浏览一个文件并选择要上传的文件时,它会显示相应的预览,比如.txt、.csv、.xls或xlsx等等。简单的方法或者复杂的方法都可以。我如何实现这样的目标?

html file

html文件

<form id="form1" runat="server">
    <input type='file' id="imgInp" />
    <img id="blah" src="#" alt="your image" />
</form>

here the js

这里的js

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#blah').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$("#imgInp").change(function(){
    readURL(this);
});

1 个解决方案

#1


1

There is no way to do this without converting the file first. There are third party services (box view api, google docs viewer), that convert the file and display it in browser, but you have to upload the file first, which kind of defeats the point.

如果不首先转换文件,就没有办法做到这一点。有第三方服务(box view api,谷歌docs查看器),它们转换文件并在浏览器中显示,但是您必须先上传文件,这就违背了这一点。

更多相关文章

  1. 静态h5页面没有后台直接访问本地json文件
  2. Mvc 5和实体框架6中的Jquery多文件上载问题
  3. 单击文件输入后,Fancybox正在关闭
  4. Struts2 使用Jquery+ajax 文件上传
  5. 为什么我不能在同一个js文件中建立两个cleave.js格式的字段?
  6. (文件).ready是全球范围的吗?
  7. 当AJAX响应来自PHP文件时,如何显示以消息为中心的加载器图像&防止
  8. JQuery------获取中的文件内容
  9. 如何在Rails 4(使用jquery)中上传多个文件?

随机推荐

  1. 23 个初级 Vue.js 面试题[每日前端夜话0x
  2. 深入理解Java中的迭代器
  3. 再谈多态
  4. Java面试题全集(3)
  5. 03 Linux的常用命令
  6. 你可能不知道的15个 Git 命令[每日前端夜
  7. 能用 CSS 能播放声音吗?[每日前端夜话0xF1
  8. Java面试题全集(2)
  9. 15个 Vue.js 高级面试题[每日前端夜话0xF
  10. 英文都不懂.碰都没碰过编程软件!是心理的