phonegap的下载方法及文件系统
来源:互联网 发布:删除旧版本windows 编辑:程序博客网 时间:2024/06/01 09:38
参考:http://docs.phonegap.com/en/2.9.0/cordova_file_file.md.html#File
phonegap的下载方法:
var fileTransfer = new FileTransfer();var uri = encodeURI("http://www.google.com.hk/images/srpr/logo4w.png");fileTransfer.download( uri, filePath,/*filePath的根目录:/var/mobile/Applications/4CBF4219-B2D2-420C-B0CC-32CA1D6DD42E/Documents/ 程序内www的路径为:var/mobile/Applications/4CBF4219-B2D2-420C-B0CC-32CA1D6DD42E/middleware.app/www/ 当phonegap加载完成后会console.log出中间的唯一标识,也可以通过jquery获取加载过来的某个js文件的路径来获得,应该注意的是,这里的filePath==/var/mobile/Applications/4CBF4219-B2D2-420C-B0CC-32CA1D6DD42E/Documents/logo4w.png*/ function(entry) { /*成功下载回调函数*/ console.log("download complete: " + entry.fullPath);/*下载的文件的完整路径*/ }, /*下载失败回调函数*/ function(error) { console.log("download error source " + error.source); console.log("download error target " + error.target); console.log("upload error code" + error.code); }, false,/*是否接受所有的安全证书。官方解释为:Optional parameter, defaults to false. If set to true then it will accept all security certificates. This is useful as Android rejects self signed security certificates. Not recommended for production use. Supported on Android and iOS. (boolean)*/ { headers: { "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" } }/*官方解释为:Optional parameters, currently only supports headers (such as Authorization (Basic Authentication), etc).*/);//注:一般我都不用最后两个参数...
Phonegap的文件系统:
phonegap中要对文件操作,则应该先请求一个文件系统,成功后获得fileSystem对象后才可用,示例如下:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);function onFileSystemSuccess(fileSystem) { console.log("fileSystem.name:-------"+fileSystem.name); console.log("fileSystem.root.name:-------"+fileSystem.root.name); //创建目录 fileSystem.root.getDirectory("file_mobile/download", {create:true}, function(fileEntry){ console.log("创建目录成功,完整路径为:"+fileEntry.fullPath); }, function(){ console.log("创建目录失败");});/*getDurectiry的官方解释:path: The path to the directory to be looked up or created. Either an absolute path, or a relative path from this DirectoryEntry. (DOMString)options: Options to specify whether the directory is to be created if it doesn't exist. (Flags)successCallback: A callback that executes with a DirectoryEntry object. (Function)errorCallback: A callback that executes if an error occurs when creating or looking up the directory. Invoked with a FileError object. (Function)*/ var _localFile = "file_mobile/download/logo4w.png"; var _url = "http://www.google.com.hk/images/srpr/logo4w.png"; //查找文件 fileSystem.root.getFile(_localFile, {create:true}, function(fileEntry){ console.log("fileEntry.fullPath="+fileEntry.fullPath); }, function(){ });/*getFile的官方解释:path: The path to the file to be looked up or created. Either an absolute path, or a relative path from this DirectoryEntry. (DOMString)options: Options to specify whether the file is created if it doesn't exist. (Flags)successCallback: A callback that is passed a FileEntry object. (Function)errorCallback: A callback that executes if an error occurs when creating or looking up the file. Invoked with a FileError object. (Function)*/}
- phonegap的下载方法及文件系统
- ③phoneGap 3.4 android 下载及安装。
- phonegap plugin的创建方法
- PhoneGap写文件的方法
- 开发web app并且使用phonegap下载及打开附件
- 在xcode环境下创建phonegap项目方法及一个简单的自定义插件示例
- Linux文件系统-文件权限的含义及修改方法
- PhoneGap的工作原理及架构基础
- ios phoneGap的安装及使用
- 文件的上传、下载及删除方法
- phonegap中退出应用的方法
- phonegap文件系统信息对象FileSystem
- phonegap源码下载地址
- PhoneGap文件下载
- PhoneGap源代码下载地址
- phonegap下载地址
- u-boot通过nfs从服务器下载内核,并且启动内核,挂载根文件系统的方法
- PhoneGap 简介及原理
- VS中的路径宏 vc++中OutDir、ProjectDir、SolutionDir各种路径
- 交换机与HUB的区别 及 hub抓包记录
- 深度解析:清理烂代码
- DB2性能调优
- 从零开始学android
- phonegap的下载方法及文件系统
- 【游戏引擎】深入分析Cocos2d-x 2.0中的“纹理”(一)
- inline
- arcgis for flex 中Panel拖动
- poj 1664 放苹果(递推)
- 数据分析参考资料整理
- C# 文件下载相关代码
- WinForm-TextRenderer和Graphics的一些区别
- postgresSQL服务进程体系结构