文件夹数据库处理逻辑

publicclass DbFolder

{

JSONObject root;

public DbFolder()

{

this.root = new JSONObject();

this.root.put("f_id", "");

this.root.put("f_nameLoc", "根目录");

this.root.put("f_pid", "");

this.root.put("f_pidRoot", "");

}

/**

* 将JSONArray转换成map

* @param folders

* @return

*/

public Map<String, JSONObject> toDic(JSONArray folders)

{

Map<String, JSONObject> dt = new HashMap<String, JSONObject>();

for(int i = 0 , l = folders.size();i<l;++i)

{

JSONObject o = folders.getJSONObject(i);

String id = o.getString("f_id");

dt.put(id, o);

}

return dt;

}

public Map<String, JSONObject> foldersToDic(String pidRoot)

{

//默认加载根目录

String sql = String.format("select f_id,f_nameLoc,f_pid,f_pidRoot from up6_folders where f_pidRoot='%s'", pidRoot);

SqlExec se = new SqlExec();

JSONArray folders = se.exec("up6_folders", sql, "f_id,f_nameLoc,f_pid,f_pidRoot","");

returnthis.toDic(folders);

}

public ArrayList<JSONObject> sortByPid( Map<String, JSONObject> dt, String idCur, ArrayList<JSONObject> psort) {

String cur = idCur;

while (true)

{

//key不存在

if (!dt.containsKey(cur)) break;

JSONObject d = dt.get(cur);//查父ID

psort.add(0, d);//将父节点排在前面

cur = d.getString("f_pid").trim();//取父级ID

if (cur.trim() == "0") break;

if ( StringUtils.isBlank(cur) ) break;

}

return psort;

}

public JSONArray build_path_by_id(JSONObject fdCur) {

String id = fdCur.getString("f_id").trim();//

String pidRoot = fdCur.getString("f_pidRoot").trim();//

//根目录

ArrayList<JSONObject> psort = new ArrayList<JSONObject>();

if (StringUtils.isBlank(id))

{

psort.add(0, this.root);

return JSONArray.fromObject(psort);

}

//构建目录映射表(id,folder)

Map<String, JSONObject> dt = this.foldersToDic(pidRoot);

//按层级顺序排列目录

psort = this.sortByPid(dt, id, psort);

SqlExec se = new SqlExec();

//是子目录->添加根目录

if (!StringUtils.isBlank(pidRoot))

{

JSONObject root = se.read("up6_files"

, "f_id,f_nameLoc,f_pid,f_pidRoot"

, new SqlParam[] { new SqlParam("f_id", pidRoot) });

psort.add(0, root);

}//是根目录->添加根目录

elseif (!StringUtils.isBlank(id) && StringUtils.isBlank(pidRoot))

{

JSONObject root = se.read("up6_files"

, "f_id,f_nameLoc,f_pid,f_pidRoot"

, new SqlParam[] { new SqlParam("f_id", id) });

psort.add(0, root);

}

psort.add(0, this.root);

return JSONArray.fromObject(psort);

}

public FileInf read(String id) {

SqlExec se = new SqlExec();

String sql = String.format("select f_pid,f_pidRoot,f_pathSvr from up6_files where f_id='%s' union select f_pid,f_pidRoot,f_pathSvr from up6_folders where f_id='%s'", id,id);

JSONArray data = se.exec("up6_files", sql, "f_pid,f_pidRoot,f_pathSvr","");

JSONObject o = (JSONObject)data.get(0);

FileInf file = new FileInf();

file.id = id;

file.pid = o.getString("f_pid").trim();

file.pidRoot = o.getString("f_pidRoot").trim();

file.pathSvr = o.getString("f_pathSvr").trim();

return file;

}

public Boolean exist_same_file(String name,String pid)

{

SqlWhereMerge swm = new SqlWhereMerge();

swm.equal("f_nameLoc", name.trim());

swm.equal("f_pid", pid.trim());

swm.equal("f_deleted", 0);

String sql = String.format("select f_id from up6_files where %s ", swm.to_sql());

SqlExec se = new SqlExec();

JSONArray arr = se.exec("up6_files", sql, "f_id", "");

return arr.size() > 0;

}

/**

* 检查是否存在同名目录

* @param name

* @param pid

* @return

*/

public Boolean exist_same_folder(String name,String pid)

{

SqlWhereMerge swm = new SqlWhereMerge();

swm.equal("f_nameLoc", name.trim());

swm.equal("f_deleted", 0);

swm.equal("LTRIM (f_pid)", pid.trim());

String where = swm.to_sql();

String sql = String.format("(select f_id from up6_files where %s ) union (select f_id from up6_folders where %s)", where,where);

SqlExec se = new SqlExec();

JSONArray fid = se.exec("up6_files", sql, "f_id", "");

return fid.size() > 0;

}

public Boolean rename_file_check(String newName,String pid)

{

SqlExec se = new SqlExec();

JSONArray res = se.select("up6_files"

, "f_id"

,new SqlParam[] {

new SqlParam("f_nameLoc",newName)

,new SqlParam("f_pid",pid)

},"");

return res.size() > 0;

}

public Boolean rename_folder_check(String newName, String pid)

{

SqlExec se = new SqlExec();

JSONArray res = se.select("up6_folders"

, "f_id"

, new SqlParam[] {

new SqlParam("f_nameLoc",newName)

,new SqlParam("f_pid",pid)

},"");

return res.size() > 0;

}

publicvoid rename_file(String name,String id) {

SqlExec se = new SqlExec();

se.update("up6_files"

, new SqlParam[] { new SqlParam("f_nameLoc", name) }

, new SqlParam[] { new SqlParam("f_id", id) });

}

publicvoid rename_folder(String name, String id, String pid) {

SqlExec se = new SqlExec();

se.update("up6_folders"

, new SqlParam[] { new SqlParam("f_nameLoc", name) }

, new SqlParam[] { new SqlParam("f_id", id) });

}

}

1.在webuploader.js大概4880行代码左右,在动态生成的input组件的下面(也可以直接搜索input),增加webkitdirectory属性。

function FileUploader(fileLoc, mgr)

{

var _this = this;

this.id = fileLoc.id;

this.ui = { msg: null, process: null, percent: null, btn: { del: null, cancel: null,post:null,stop:null }, div: null};

this.isFolder = false; //不是文件夹

this.app = mgr.app;

this.Manager = mgr; //上传管理器指针

this.event = mgr.event;

this.Config = mgr.Config;

this.fields = jQuery.extend({}, mgr.Config.Fields, fileLoc.fields);//每一个对象自带一个fields幅本

this.State = this.Config.state.None;

this.uid = this.fields.uid;

this.fileSvr = {

pid: ""

, id: ""

, pidRoot: ""

, f_fdTask: false

, f_fdChild: false

, uid: 0

, nameLoc: ""

, nameSvr: ""

, pathLoc: ""

, pathSvr: ""

, pathRel: ""

, md5: ""

, lenLoc: "0"

, sizeLoc: ""

, FilePos: "0"

, lenSvr: "0"

, perSvr: "0%"

, complete: false

, deleted: false

};//json obj,服务器文件信息

this.fileSvr = jQuery.extend(this.fileSvr, fileLoc);

2.可以获取路径

this.open_files = function (json)

{

for (var i = 0, l = json.files.length; i < l; ++i)

{

this.addFileLoc(json.files[i]);

}

setTimeout(function () { _this.PostFirst(); },500);

};

this.open_folders = function (json)

{

for (var i = 0, l = json.folders.length; i < l; ++i) {

this.addFolderLoc(json.folders[i]);

}

setTimeout(function () { _this.PostFirst(); }, 500);

};

this.paste_files = function (json)

{

for (var i = 0, l = json.files.length; i < l; ++i)

{

this.addFileLoc(json.files[i]);

}

};

后端代码逻辑大部分是相同的,目前能够支持MySQL,Oracle,SQL。在使用前需要配置一下数据库,可以参考我写的这篇文章:http://blog.ncmem.com/wordpress/2019/08/07/java超大文件上传与下载/

web超大文件上传的更多相关文章

  1. java+web+超大文件上传

    javaweb上传文件 上传文件的jsp中的部分 上传文件同样可以使用form表单向后端发请求,也可以使用 ajax向后端发请求 1.通过form表单向后端发送请求 <form id=" ...

  2. WEB超大文件上传与下载

    1.介绍enctype enctype 属性规定发送到服务器之前应该如何对表单数据进行编码. enctype作用是告知服务器请求正文的MIME类型(请求消息头content-type的作用一样) 1. ...

  3. Web Uploader文件上传插件

    http://www.jq22.com/jquery-info2665   插件描述:WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现 ...

  4. Web Uploader文件上传&&使用webupload有感(黄色部分)

    引入资源 使用Web Uploader文件上传需要引入三种资源:JS, CSS, SWF. <!--引入CSS--> <link rel="stylesheet" ...

  5. 七牛云存储的 Javascript Web 前端文件上传

    因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,七牛云存储的 Web 前端文件上传 七牛是不错的云存储产品,特别是有免费的配额可 ...

  6. 4GB以上超大文件上传和断点续传服务器的实现

    随着视频网站和大数据应用的普及,特别是高清视频和4K视频应用的到来,超大文件上传已经成为了日常的基础应用需求. 但是在很多情况下,平台运营方并没有大文件上传和断点续传的开发经验,往往在网上找一些简单的 ...

  7. Java超大文件上传解决办法

    这里只写后端的代码,基本的思想就是,前端将文件分片,然后每次访问上传接口的时候,向后端传入参数:当前为第几块文件,和分片总数 下面直接贴代码吧,一些难懂的我大部分都加上注释了: 上传文件实体类: 看得 ...

  8. java+web+多级文件上传

    文件夹数据库处理逻辑 publicclass DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject(); ...

  9. php+超大文件上传

    1 背景 用户本地有一份txt或者csv文件,无论是从业务数据库导出.还是其他途径获取,当需要使用蚂蚁的大数据分析工具进行数据加工.挖掘和共创应用的时候,首先要将本地文件上传至ODPS,普通的小文件通 ...

随机推荐

  1. Python习题004

    作业一:三迁举办选“帅气男孩”,评委打分可以输入打分,要求分数必须大于5,小于10: 方法一 i = 1 while i < 6: score = input("请%d评委打分:&qu ...

  2. 给内部类对象数组属性赋值时报错:Exception in thread "main" java.lang.NullPointerException

    前言 1255: 打怪升级(Java),写这个题目程序的时候,控制台提示如下错误: Exception in thread "main" java.lang.NullPointer ...

  3. 插入排序——C语言

    插入排序 插入排序(Insertion-Sort)的算法描述是一种简单直观的排序算法.它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入.  (每步将一个待 ...

  4. SSM集成

    SSM集成   Spring和各个框架的整合   Spring目前是JavaWeb开发中最终的框架,提供一站式服务,可以其他各个框架整合集成   Spring整合方案   SSH Ssh是早期的一种整 ...

  5. js 根据 数组条件 简单查询的方法临时保存

    let array = [{ date: '2016-05-02', name: 'Ethan', status: 'success', total: '81' }, { date: '2016-05 ...

  6. 红帽linux系统开机自启动脚本。

    其实很多东西在最后完成以后会觉得也就那样,有意思的是探究的过程. 前段时间老板要求把一个程序做成linux系统开机自启动脚本的模式. 首先你需要写一个脚本. 我这边建立了一个.sh的脚本,就是用脚本启 ...

  7. vs professional 2019 离线安装包下载方法

    run->cmd D:\vsprofessional2019>vs_professional__1254024763..exe --layout D:\vsprofessional2019 ...

  8. (五)Maven中的聚合和继承

    一.为什么要聚合? 定义:我们在开发过程中,创建了2个以上的模块,每个模块都是一个独立的maven project,在开始的时候我们可以独立的编译和测试运行每个模块,但是随着项目的不断变大和复杂化,我 ...

  9. [JZOJ5897]密匙--哈希骚操作

    [JZOJ5897]密匙--哈希骚操作 题目链接 太懒了自行Google 前置技能 二分/倍增求LCP e.g TJOI2017DNA 分析 这题看了样例解释才知道什么意思 本以为自己身为mo法师蛤希 ...

  10. ubuntu16下 Oracle安装完毕,测试是否安装成功的步骤

    1.查看oracle的环境变量,在终端输入命令 echo $ORACLE_BASE echo $ORACLE_HOME echo $PATH 看输出是不是安装时设置的路径 2.开启监听器 lsnrct ...