文件夹数据库处理逻辑

public class 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","");

return this.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);

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

else if (!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;

}

public void 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) });

}

public void 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超大文件上传与下载/

ASP.NET大文件分片上传的更多相关文章

  1. Webuploader 大文件分片上传

    百度Webuploader 大文件分片上传(.net接收)   前阵子要做个大文件上传的功能,找来找去发现Webuploader还不错,关于她的介绍我就不再赘述. 动手前,在园子里找到了一篇不错的分片 ...

  2. java springboot 大文件分片上传处理

    参考自:https://blog.csdn.net/u014150463/article/details/74044467 这里只写后端的代码,基本的思想就是,前端将文件分片,然后每次访问上传接口的时 ...

  3. vue+大文件分片上传

    最近公司在使用vue做工程项目,实现大文件分片上传. 网上找了一天,发现网上很多代码都存在很多问题,最后终于找到了一个符合要求的项目. 工程如下: 对项目的大文件上传功能做出分析,怎么实现大文件分片上 ...

  4. iOS大文件分片上传和断点续传

    总结一下大文件分片上传和断点续传的问题.因为文件过大(比如1G以上),必须要考虑上传过程网络中断的情况.http的网络请求中本身就已经具备了分片上传功能,当传输的文件比较大时,http协议自动会将文件 ...

  5. js实现大文件分片上传的方法

    借助js的Blob对象FormData对象可以实现大文件分片上传的功能,关于Blob和FormData的具体使用方法可以到如下地址去查看FormData 对象的使用Blob 对象的使用以下是实现代码, ...

  6. Node + js实现大文件分片上传基本原理及实践(一)

    _ 阅读目录 一:什么是分片上传? 二:理解Blob对象中的slice方法对文件进行分割及其他知识点 三. 使用 spark-md5 生成 md5文件 四. 使用koa+js实现大文件分片上传实践 回 ...

  7. thinkphp+webuploader实现大文件分片上传

    大文件分片上传,简单来说就是把大文件切分为小文件,然后再一个一个的上传,到最后由这些小文件再合并成原来的文件 webuploader下载地址及其文档:http://fex.baidu.com/webu ...

  8. 在React中使用WebUploader实现大文件分片上传的踩坑日记!

    前段时间公司项目有个大文件分片上传的需求,项目是用React写的,大文件分片上传这个功能使用了WebUploader这个组件. 具体交互是: 1. 点击上传文件button后出现弹窗,弹窗内有选择文件 ...

  9. nodeJs + js 大文件分片上传

    简单的文件上传 一.准备文件上传的条件: 1.安装nodejs环境 2.安装vue环境 3.验证环境是否安装成功 二.实现上传步骤 1.前端部分使用 vue-cli 脚手架,搭建一个 demo 版本, ...

随机推荐

  1. 2.3负载均衡:Ribbon

    基于上一篇文章的工程,启动eureka-server 工程:启动service-hi工程,它的端口为8765:将service-hi的配置文件的端口改为8763,并启动,这时你会发现:service- ...

  2. 模块和包,logging模块

    模块和包,logging日志 1.模块和包 什么是包? 只要文件夹下含有__init__.py文件就是一个包. 假设文件夹下有如下结构 bake ├── test.py ├── __init__.py ...

  3. 分享一些JVM常见的面试题(转)

    出处:  分享一些JVM常见的面试题 前言: 在遨游了一番 Java Web 的世界之后,发现了自己的一些缺失,所以就着一篇深度好文:知名互联网公司校招 Java 开发岗面试知识点解析 ,来好好的对 ...

  4. shell习题第17题:检测磁盘

    [题目要求] 写一个shell脚本,检测所有磁盘分区使用率和inode使用率并记录到以当天日期命名的日志文件里,当发现某个分区容量或者inode使用量大于85%时候,发邮件提醒 [核心要点] df d ...

  5. 第二章、http协议及嗅探抓包--http协议详解

    初识http协议    hypertext trandfer protocol 超文本传输协议,是一种分布式,合作式,多媒体信息系统服务,面向应用层的协议.使用最广泛的应用层协议,基于传输层的TCP协 ...

  6. Ocelot + Consul的demo

    参考大佬的博客写的:https://www.cnblogs.com/alan-lin/p/9126155.html:也可以参考这篇博客:https://www.cnblogs.com/axzxs200 ...

  7. YOLOV3 训练WIDER_FACE

    1. dowload the img and labels : http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/index.html 2.

  8. Newtonsoft.Json基本用法

    1.将一个 Object 序列化成 JSON: DataSet detail = sqlDB.GetDataSet(string.Format("select * from student ...

  9. Spring cloud实战——服务提供者

    目录讲解: 一.服务提供者与服务消费者的概念 二.编写一个服务提供者的测试类(code) 1.1. 使用微服务构建的是分布式系统,微服务之间通过网络进行通信.我们使用微服务提供者与服务消费者来描述微服 ...

  10. 第七章、Ajango自带auth模块

    目录 第七章.Ajango自带auth模块 一.什么是auth auth是django自带的用户认证模块 二.auth模块的常用方法 三.拓展默认的auth_user表 第七章.Ajango自带aut ...