HTML5 filesystem: 网址

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:文件的内容html

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);
    })
});

 

更多:web

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

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

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

相关文章
相关标签/搜索