gaus
gaus
  • 发布:2015-12-26 13:33
  • 更新:2015-12-27 15:22
  • 阅读:1453

app自创建目录,能创建但不能写进文件,手工创建则能写进,是权限的问题吗

分类:MUI

app创建目录,如_doc/tmp,能创建但不能写进文件。使用91助手完全手工创建则能写进文件,是权限的问题吗?

文档里没有看到权限相关的内容

2015-12-26 13:33 负责人:无 分享
已邀请:
DCloud_heavensoft

DCloud_heavensoft

plus.io和plus.downloader可以写入_doc目录,只是不能写入_www目录。_www目录更新要通过5+专门的更新api来操作。参考文档-app教程-app更新

gaus

gaus (作者)

@DCloud_heavensoft

1、确实能写入_doc目录,但不能写到_doc下面的多级子目录,比如_doc/tmp/image/abc.jpg
2、这里的_doc/tmp/image/,就是通过plus.io创建的,可以看到,确实创建成功。

但是,往这个目录下再写文件时,比如_doc/tmp/image/abc.jpg,这个abc.jpg就没办法写进去。

3、如果我不使用plus.io/plus.downloader这种系统方法创建目录,而是手工创建(91助手),则写文件:_doc/tmp/image/abc.jpg又能写进去了,感觉是类似unix权限不足的问题。

maq

maq

实践证明,创建子目录、创建文件和写入文件、改写文件都没有问题。代码如下:

<!DOCTYPE html>  
<html>  
<head>  
<meta charset="utf-8">  
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
<title></title>  
<script src="js/mui.min.js"></script>  
<link href="css/mui.min.css" rel="stylesheet" />  
</head>  
<body>  
<button id="btn-test">test</button>  
<script type="text/javascript" charset="utf-8">  
mui.init();  
mui.plusReady(function() {  
    var fnError = function(ex) {  
        console.log(ex);  
    };  
    mui('#btn-test')[0].addEventListener('tap', function() {  
        plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {  
            console.log(fs.name);  
            var entry = fs.root;  
            console.log(entry.fullPath);  
            entry.getDirectory('sub_dir_1', {create:true}, function(sub_dir_1) {  
                console.log(sub_dir_1.fullPath);  
                sub_dir_1.getDirectory('sub_dir_2', {create:true}, function(sub_dir_2) {  
                    console.log(sub_dir_2.fullPath);  
                    sub_dir_2.getFile('new_file', {create:true}, function(new_file) {  
                        console.log(new_file.fullPath);  
                        new_file.createWriter(function(writer) {  
                            writer.write('now: ' + new Date().toString());  
                        }, fnError);  
                    }, fnError);  
                }, fnError);  
            }, fnError);  
        }, fnError);  
    });  
})  
</script>  
</body>  
</html>

运行环境是 Genymotion 模拟器,手机型号为【Samsung Galaxy S3 - 4.2.2 - API 17】。

maq

maq

不过我倒是注意到一个问题:entry.fullPath 看到的路径,用 adb shell 是查不到的,实际存在的是另外一个路径。

也就是说,如果用 entry.fullPath 再拼接出一个全路径的话,是不可用的。

gaus

gaus (作者)

@maq

多谢!

不过我也用类似代码创建目录,但写文件时不行,不知为何。我再换个手机试试,这个酷派经常有一些诡异的调试问题,console.log也无法输出。

  • maq

    你可以试试【同样的代码】结果如何,如果没问题的话,就不是系统的原因了。

    2015-12-28 08:57

  • gaus (作者)

    没错:)

    2015-12-29 08:45

  • maq

    查明原因了么?

    2015-12-29 09:07

该问题目前已经被锁定, 无法添加新回复