2013年10月24日 星期四

javascript-create-file-download


inf : http://stackoverflow.com/questions/7160720/create-a-file-using-javascript-in-chrome-on-client-side


    window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, function(fs) {
        fs.root.getFile('test.bin', {create: true}, function(fileEntry) {
            fileEntry.createWriter(function(fileWriter) {
                var arr = new Uint8Array(3);
   
                arr[0] = 97;
                arr[1] = 98;
                arr[2] = 99;
   
                var blob = new Blob([arr]);
   
                fileWriter.addEventListener("writeend", function() {
                    // navigate to file, will download
                    location.href = fileEntry.toURL();
                }, false);
   
                fileWriter.write(blob);
            }, function() {});
        }, function() {});
    }, function() {});

沒有留言:

張貼留言