admin管理员组文章数量:1313112
I am updating an app from phonegap 2.* to cordova 3.4 Things are running smooth now, only the file download is not working.
I need to download a file from the internet (host edited) and store it as an JSON file, to have the contents processed later on.
The download is working fine, the file will be shown in the filesystem, but the FileReader does not fire the onloadend
event.
I have tried a few things like onprogress
or onerror
events, also file.toURI
and FileReader.readAsDataURL
- nothing worked. Anybody any ideas?
Notes:
app.log
can be seen as an alias forconsole.log
print_r
is defined in another file, working fine- The downloaded file is just a few kB, shouldn't be a performance issue
- Running on iOS hardware
Full code (extracted and shortened):
var fileTransfer = new FileTransfer();
var loadingStatus = 0;
fileTransfer.onprogress = function (progressEvent) {
// if we have the plete length we can calculate the percentage, otherwise just count up
if (progressEvent.lengthComputable) {
loadingStatus = Math.floor(progressEvent.loaded / progressEvent.total * 100);
} else {
loadingStatus++;
}
app.log('Transfer Progress: ' + loadingStatus);
};
fileTransfer.download(
encodeURI(''),
'cdvfile://localhost/persistent/import.json',
function (file) {
var FileReader = new FileReader();
FileReader.onloadend = function (evt) {
app.log('Filereader onloadend');
app.log(evt);
};
FileReader.readAsText(file);
},
function (error) {
// FileTransfer failed
app.log("FileTransfer Error: " + print_r(error));
}
);
I am updating an app from phonegap 2.* to cordova 3.4 Things are running smooth now, only the file download is not working.
I need to download a file from the internet (host edited) and store it as an JSON file, to have the contents processed later on.
The download is working fine, the file will be shown in the filesystem, but the FileReader does not fire the onloadend
event.
I have tried a few things like onprogress
or onerror
events, also file.toURI
and FileReader.readAsDataURL
- nothing worked. Anybody any ideas?
Notes:
app.log
can be seen as an alias forconsole.log
print_r
is defined in another file, working fine- The downloaded file is just a few kB, shouldn't be a performance issue
- Running on iOS hardware
Full code (extracted and shortened):
var fileTransfer = new FileTransfer();
var loadingStatus = 0;
fileTransfer.onprogress = function (progressEvent) {
// if we have the plete length we can calculate the percentage, otherwise just count up
if (progressEvent.lengthComputable) {
loadingStatus = Math.floor(progressEvent.loaded / progressEvent.total * 100);
} else {
loadingStatus++;
}
app.log('Transfer Progress: ' + loadingStatus);
};
fileTransfer.download(
encodeURI('http://www.example./export'),
'cdvfile://localhost/persistent/import.json',
function (file) {
var FileReader = new FileReader();
FileReader.onloadend = function (evt) {
app.log('Filereader onloadend');
app.log(evt);
};
FileReader.readAsText(file);
},
function (error) {
// FileTransfer failed
app.log("FileTransfer Error: " + print_r(error));
}
);
Share
Improve this question
asked May 13, 2014 at 7:07
VestalisVestalis
2702 gold badges4 silver badges11 bronze badges
2 Answers
Reset to default 7The File API has been updated. See this post: https://groups.google./forum/#!topic/phonegap/GKoTOSqD2kc
file.file(function(e) {
console.log("called the file func on the file ob");
var reader = new FileReader();
reader.onloadend = function(evt) {
app.log('onloadend');
app.log(evt.target.result);
};
reader.readAsText(e);
});
Cant verify this at the moment but since 3.0, Cordova implements device-level APIs as plugins. Use the CLI's plugin mand, described in The Command-line Interface, to add or remove this feature for a project:
$ cordova plugin add https://git-wip-us.apache/repos/asf/cordova-plugin-file.git
$ cordova plugin rm org.apache.cordova.core.file
Did you add the plugin to your project?
本文标签: javascriptCordova 34 FileReader not working (no onloadend)Stack Overflow
版权声明:本文标题:javascript - Cordova 3.4 FileReader not working (no onloadend) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741928782a2405450.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论