BGe*_*cko 2 javascript android cordova phonegap-build
我已经看到了几个不同的示例,说明如何使用Phonegap File API将文件从一个目录复制到另一个目录,但是无法将文件从我的应用程序文件夹复制到根目录中的现有文件夹.File API文档非常模糊,我一直在应用程序目录中找不到文件.
我可以使用root.toURL()访问sdcard根文件夹文件:/// storage/emulated/0 /并读取和写入它,我似乎无法访问我的应用程序文件夹.
Phonegap Build配置文件中的权限.
<gap:plugin name="org.apache.cordova.file" version="1.3.1" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />
Run Code Online (Sandbox Code Playgroud)
任何帮助或示例都会很棒.
谢谢,
RG
wwwPath = cordova.file.applicationDirectory;
var fp = "temp/myfile.txt";
var fileDestPath = "tempFolder/";
function copyFile(){
var basePath = wwwPath+fp;
window.resolveLocalFileSystemURL(basePath, function(fileEntry){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
var copyToPath = fileSystem.root.toURL()+fileDestPath;
fileEntry.copyTo(copyToPath, 'newFileName.txt', function(){
alert("file copy success");
},fileCopyFail);
},fileCopyFail);
},fileCopyFail);
function fileCopyFail(error) {
alert(error);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以使用FileTransfer将文件下载并存储到不同的位置:
// get base url for index.html
var baseUrl = location.href.replace("/index.html", "");
var fp = "temp/myfile.txt";
var fileDestPath = "tempFolder/";
function copyFile(){
var sourceFilePath = baseUrl + "/" +fp;
var targetFilePath = fileSystem.root.toURL()+fileDestPath;
var ft = new FileTransfer();
ft.download(
sourceFilePath,
targetFilePath,
function(entry){
alert("file copy success")
},
function(error){
alert(error);
}
);
Run Code Online (Sandbox Code Playgroud)
正如我最近发现的,这不适用于Windows 81,但我在Android和iOS上成功测试了它.
归档时间: |
|
查看次数: |
5077 次 |
最近记录: |