Ext.device.filesystem.FileEntry.read() - 类型:"text" returns 空白文件
Ext.device.filesystem.FileEntry.read() - type: "text" returns blank file
我遇到了 Ext.device.filesystem.FileEntry.read() 方法的问题。当我尝试以文本形式读取 text/JSON 文件时,我得到一个空白文件。任何的想法?看起来 extjs 文件的 readastext 方法 reader 有问题。
以下无效:
var fileEntry = new Ext.device.filesystem.FileEntry(newFilePath, fileSystem);
fileEntry.read({
//type: "binaryString",
encoding: 'UTF8',
type: "text",
//type: "text",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});
但是如果我将类型从 "text" 更改为 "binaryString",它会读取文件但当然会弄乱特殊字符。
var fileEntry = new Ext.device.filesystem.FileEntry(newFilePath, fileSystem);
fileEntry.read({
type: "binaryString",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});
此致,
瓦希德
将编码更改为 'UTF-8' 即可。因此,工作代码如下:
fileEntry.read({
//type: "binaryString",
type: "text",
encoding: "UTF-8",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});
我遇到了 Ext.device.filesystem.FileEntry.read() 方法的问题。当我尝试以文本形式读取 text/JSON 文件时,我得到一个空白文件。任何的想法?看起来 extjs 文件的 readastext 方法 reader 有问题。
以下无效:
var fileEntry = new Ext.device.filesystem.FileEntry(newFilePath, fileSystem);
fileEntry.read({
//type: "binaryString",
encoding: 'UTF8',
type: "text",
//type: "text",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});
但是如果我将类型从 "text" 更改为 "binaryString",它会读取文件但当然会弄乱特殊字符。
var fileEntry = new Ext.device.filesystem.FileEntry(newFilePath, fileSystem);
fileEntry.read({
type: "binaryString",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});
此致, 瓦希德
将编码更改为 'UTF-8' 即可。因此,工作代码如下:
fileEntry.read({
//type: "binaryString",
type: "text",
encoding: "UTF-8",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});