首页 > Web开发 > 详细

HTML5 filesystem: 网址

时间:2017-02-25 16:47:05      阅读:184      评论:0      收藏:0      [点我收藏+]
FileSystem API 使用新的网址机制,(即 filesystem:),可用于填充 src 或 href 属性。
例如,如果您要显示某幅图片且拥有相应的 fileEntry,您可以调用 toURL() 获取该文件的 filesystem: 网址:
var img = document.createElement(‘img‘);  
img.src = fileEntry.toURL(); // filesystem:http://example.com/temporary/myfile.png  
document.body.appendChild(img);  
另外,如果您已具备 filesystem: 网址,可使用 resolveLocalFileSystemURL() 找回 fileEntry:
window.resolveLocalFileSystemURL = window.resolveLocalFileSystemURL ||  
                                   window.webkitResolveLocalFileSystemURL;  
  
var url = ‘filesystem:http://example.com/temporary/myfile.png‘;  
window.resolveLocalFileSystemURL(url, function(fileEntry) {  
  ...  
});  

示例1,读取filesystem:文件的内容

window.resolveLocalFileSystemURL = window.resolveLocalFileSystemURL ||
                                    window.webkitResolveLocalFileSystemURL;
var url = ‘filesystem:http://localhost:57128/temporary/test3.txt‘;
//获取fileEntry
window.resolveLocalFileSystemURL(url, function (fileEntry) {
    //读取文件 内容
    fileEntry.file(function (file) {
        var reader = new FileReader();
        reader.onload = function () {
            console.info(reader.result);
        }
        reader.readAsText(file);
    })
});

 

更多:

HTML5 本地文件操作之FileSystemAPI实例(四)

HTML5 本地文件操作之FileSystemAPI实例(三)

HTML5 本地文件操作之FileSystemAPI实例(二)

HTML5 filesystem: 网址

原文:http://www.cnblogs.com/tianma3798/p/6441959.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!