Getting content of a local file without uploading

2019-04-29 09:48发布

This question already has an answer here:

I'm writing an offline webapp that allows user to select local file, modify it and than saves a copy also locally. Is it possible without any server (I can upload a file and return base64 of it, but it's not much of a offline)? App needs to work only on Google Chrome, so maybe I should look here?

3条回答
看我几分像从前
2楼-- · 2019-04-29 09:58
 input = document.getElementById(inputId);          

 var reader = new FileReader();

 reader.onload = function (e) {
     base64 = e.target.result;
 };

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

where input is an element <input type='file'></input>. Also works for an input that can select multiple files.

查看更多
我只想做你的唯一
3楼-- · 2019-04-29 10:15

To work with files in the browser I use downloadify. In order to make it work with paths containing "file://" you need to allow for downloadify.swf access to the file system on the settings.

查看更多
相关推荐>>
4楼-- · 2019-04-29 10:19
登录 后发表回答