Preview .doc/.docx/.pdf files before uploading to server

前端 未结 8 700
抹茶落季
抹茶落季 2021-02-02 11:01

I\'m using HTML5 File API to get some document(.doc/.docx/.pdf) uploaded. And I want to show that document preview before uploading it to server. Is there any way to do such thi

8条回答
  •  被撕碎了的回忆
    2021-02-02 11:32

    Not sure if anyone still checks this thread, but i thought i'd share what i did. Directly showing a preview isn't possible, but you can create a blob object of the selected file. Something like this (jQuery):

    $('#input').change(function (event) {
        var file = URL.createObjectURL(event.target.files[0]);
        $('element').append('' + event.target.files[0].name + '');
    });
    

    This link will open a new browser tab and shows/downloads the file. This isn't really pretty but it works. Here's an example: https://jsfiddle.net/j9gw023b/3/

提交回复
热议问题