本文主要包含hbuilder mui,hbuilder mui视频教程,hbuilder mui教程,hbuilder mui api,hbuilder mui app等相关知识,教程希望在学习及工作中可以帮助到您
");
</div>
本文对plus.download做了简单的封装。通过common.cache.getFIle获取图片本地链接。 下载的代码块中没有指定下载的文件名及扩展名,我使用的是云服务器,获取的链接是没有文件扩展名的,故而没有做详细的限制。
- (function(com){
- var hashCode = function(str) {
- var hash = 0;
- if (!str || str.length == 0) return hash;
- for (i = 0; i < str.length; i++) {
- char = str.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash = hash & hash; // Convert to 32bit integer
- }
- return hash;
- };
- com.hashCode=hashCode;
- /**
- *存储当前下载路径www.bcty365.com
- */
- var cache = {};
- cache.getFile = function(netPath, cb) {
- var filePathCache = getLocalFileCache(netPath);
- if (filePathCache) {
- return cb(filePathCache);
- } else {
- Filedownload(netPath, function(localPath) {
- return cb(localPath);
- });
- }
- };
- //下载
- var Filedownload = function(netPath, callback) {
- var dtask = plus.downloader.createDownload(netPath, {}, function(d, status) {
- // 下载完成
- if (status == 200) {
- plus.io.resolveLocalFileSystemURL(d.filename, function(entry) {
- setLocalFileCache(netPath, entry.toLocalURL());
- callback(entry.toLocalURL()); //获取当前下载路径
- });
- }
- });
- dtask.start();
- };
- function getLocalFileCache(netPath) {
- var FILE_CACHE_KEY = "filePathCache_" + common.hashCode(netPath);
- var localUrlObj = myStorage.getItem(FILE_CACHE_KEY);
- return localUrlObj;
- }