ionic cordova file download and load
1.先添加插件
cordova plugin add org.apache.cordova.file
cordova plugin add org.apache.cordova.file-transfer
2. 在index.html 中添加
<img width="80px" height="80px" id="smallImage" />
3.在index.js中添加
document.addEventListener("deviceready", downloadstart, false);
/**
* 用一個文件夾download,存儲下載的圖片/文件 ;
* @return {[type]} [description]
*/
function downloadstart() {
try {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory("download", {
create: true,
exclusive: false
}, function(entry) {
var storepath = entry.toURL();
alert(storepath.toString() + '文件夹已經存在');
downloadFile(storepath, "http://www.baidu.com/img/bdlogo.png");//開始下載文件
}, function() {
console.log('创建文件夹失败');
});
}, function() {
console.log('创建文件夹失败');
});
} catch (e) {
alert(e.name + ":" + e.message);
}
}
/**
* 下載文件,
*
* @param {[string]} storefilepath [下載的文件存儲的路徑]
* @param {[string]} downloadfileurl [需要下載文件的URL 或者名稱]
* @return {[type]} [description]
*/
function downloadFile(storefilepath, downloadfileurl) {
try {
var ft = new FileTransfer();
var uri = encodeURI(downloadfileurl);
var fileURL = storefilepath + downloadfileurl.substr(downloadfileurl.lastIndexOf('/') + 1);
ft.download(
uri,
fileURL,
function(entry) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = entry.toURL();
alert("download complete: " + entry.toURL());
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false, {
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);
} catch (e) {
alert(e.name + ":" + e.message);
}
}
ionic cordova file download and load的更多相关文章
- 基于ionic+cordova+angularJs从零开始搭建自己的移动端H5 APP
这里详细介绍下如何用ionic+cordova+angularjs搭建自己的移动端app,包括环境搭建,框架使用等,具体项目已放置在github上,可下载下来自行启动. 下载地址:https://gi ...
- ionic+cordova+angularJs
ionic+cordova+angularJs 这里详细介绍下如何用ionic+cordova+angularjs搭建自己的移动端app,包括环境搭建,框架使用等,具体项目已放置在github上,可下 ...
- ionic cordova platform --help
ionic platform add android 给我报这个问题,不理解 The platform command has been renamed. To find out more, run: ...
- androidAndroid开发学习--Ionic+Cordova 环境搭建
我们看 Ionic 能给我们提供什么? 一个样式库,你可以使用它 来 装饰你的 HTML 网页 ,看起来 想 移动程序的 界面,什么 header .content.footer.grid.list ...
- Ionic Cordova 调用原生 Api 实现拍照上传 图片到服务器功能
Ionic 调用 Device 设备 Api 获取手机的设备信息 1. 找到对应的Api: https://ionicframework.com/docs/native/device/ 2. 安装相关 ...
- Ionic Cordova 环境配置window
1.安装java jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.安 ...
- 搭建 AngularJS+Ionic+Cordova 开发环境并运行一个demo
目前的手机APP有三类:原生APP,WebAPP,HybridApp:HybridApp结合了前两类APP各自的优点,越来越流行. Cordova就是一个中间件,让我们把WebAPP打包成Hybrid ...
- Ionic + Cordova 跨平台移动开发环境配置
1.下载安装JDK(根据各自系统选择32位或64位下载),安装完成之后需要做以下环境变量配置 在“系统变量”中,设置3象属性,JAVA_HOME,PATH,CLASSPATH(大小写无所谓),如果已经 ...
- npm 安装 ionic cordova
针对npm安装 ionic 和 cordova 过程很慢,且有些安装文件被墙的问题,使用如下方式解决: 1)安装cnpm npm install -g cnpm 2)然后再使用cnpm 安装 ioni ...
随机推荐
- 黄聪:C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果) (转)
一.各种旋转.改变大小 注意:先要添加画图相关的using引用. //向右旋转图像90°代码如下:private void Form1_Paint(object sender, System.Wind ...
- eclipse调试总结(转)
Debug视图 认识debug视图,红色部分框为线程堆栈视图,黄色部分框为表达式.断点.变量视图,蓝色部分为代码视图. 线程堆栈视图 分别介绍一下这几个按钮的含义: 1.表示当前实现继续运行直到下一 ...
- (C/C++) Interview in English - Class
Q: What is a class? A: A class is an expanded concept of a data structure: instead of holding only d ...
- Hibernate第一个程序
1. 下载资源:www.hibernate.org 2. 资源介绍hibernate-release-4.3.10.Final a) Documentation 相关文档 b) Lib 相关jar包 ...
- angular.js form
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- MVC ViewData和ViewBag[转]
转自:http://blog.csdn.net/a497785609/article/details/7854402#t0 视图数据可以通过ViewBag属性访问,它主要是为了从Contr ...
- REDHAT6.2配置yum源(64位)(转载)
From:http://www.dedecms8.com/db/php_bc/12322.html 1.删除redhat原有的yum rpm -aq|grep yum|xargs rpm -e --n ...
- eclipse 自动补全
在使用过程中问题又来了, 当按下空格键时会把第一行的内容自动上屏,其实很多时候就是想输一个空格而已. 解决办法: 取消之前的修改: "Auto Activation triggers for ...
- C Primer Plus(第五版)4
第四章 字符串和格式化输入输出 4.2 字符串简介 字符串(character string)就是一个或多个字符的序列.下面是一个字符串的例子: “Zing went the strings of m ...
- ubuntu14安装ambari2.2
https://cwiki.apache.org/confluence/display/AMBARI/Install+Ambari+2.2.0+from+Public+Repositories 查看是 ...