我正在使用TIZEN架构为SAMSUNG显示器开发Web应用程序。我已经实现了Filesystem API,但是现在我遇到了一个我不理解的问题而且documntaton是...让我们说稀疏。
目前,应用程序在wgt-private中创建了一个数据文件夹,因此我有wgt-private / data /。但是,在尝试解析此路径时,我收到一个File对象,这会阻止我创建文件,因为File对象不像Directory对象那样提供createFile()方法 - 显然。
创建目录的代码。实现了延迟功能以及回调,这是多余的,但是对于该线程可以忽略。 Essential主要是TIZEN resolve函数的第一次成功回调,它从Filesystem API中检索一个对象:
tizen.filesystem.resolve(
homePath,
function ( obj ) {
var exceptionThrown = false;
try {
var newDir = obj.createDirectory( path );
} catch ( e ){
Logger.debug("[DIRECTORY] Could not create directory:");
Logger.debug( e.message );
Logger.debug( e );
exceptionThrown = true;
}
// check if an exception occurred
if ( exceptionThrown == true ) {
dfd.resolve();
if ( failure_cb != null && typeof( failure_cb ) === 'function' ){
failure_cb( path );
}
} else {
dfd.resolve();
if ( success_cb != null && typeof( success_cb ) === 'function' ){
self.exists( path, success_cb, failure_cb )
}
}
},
function ( e ) {
Logger.debug("[DIRECTORY] Attempted to create directory, but could not resolve location due to error:");
dfd.resolve();
Logger.debug( e );
if ( failure_cb != null && typeof( failure_cb ) === 'function' ){
failure_cb( path );
}
}
);
这是通过检索Directory对象并调用createFile来创建文件的调用。同样存在可以忽略的延迟解析和回调。重要的是解析wgt-private / data应该给我一个Directory对象(我特意检查了成功回调被调用用于创建/数据并且它是使用createDirectory创建的)但是我收到了一个File对象:
tizen.filesystem.resolve(
'wgt-private/data',
function ( obj ) {
try {
Logger.debug( obj );
obj.createFile( filename ); // create file at location
} catch ( e ) {
Logger.debug("[FILE] Exception caught while attempting to create file " + path);
Logger.debug( e.message );
Logger.debug( e );
}
self.exists( path, success_cb, failure_cb ); // if exists --> success
},
function ( err ) {
Logger.error("[FILE] Could not create file!");
Logger.error( err );
// couldn't create file - failure-callback
if ( failure_cb != null && typeof( failure_cb ) === 'function' ){
failure_cb( path );
}
},
"rw"
);
我不明白这种行为。我可以用同样的方式解决wgt-private,但是解析一个子路径告诉我我正在解析一个文件。有谁看到我做错了什么?
答案 0 :(得分:0)
使用tizen.filesystem.resolve()函数解析位置时, 你正在解决Tizen FileSystem的位置。
'wgt-private'不是实际路径,而是表示虚拟路径。例如'file://opt/usr/abcd.yourapp'。当您将'wgt-private'参数提供给tizen.filesystem.resolve()时,它会为您解析小部件存储其信息的私有文件夹。
从Tizen Filesystem解析私人文件夹后,您必须解析数据文件夹的私人文件夹。
tizen.filesystem.resolve('wgt-private', function(obj)
{
file = obj.resolve('data');
}, function(e)
{
console.log("Error" + e.message);
}, "rw");
参考:resolve()