首页 > 其他分享 >求超大文件上传方案( HTML5 )

求超大文件上传方案( HTML5 )

时间:2022-11-30 14:12:41浏览次数:57  
标签:String 超大 pid HTML5 pidRoot new 上传 id se

文件夹数据库处理逻辑

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。在使用前需要配置一下数据库,示例代码下载地址:asp.net源码下载jsp-springboot源码下载jsp-eclipse源码下载jsp-myeclipse源码下载php源码下载csharp-winform源码下载vue-cli源码下载c++源码下载

详细配置信息及思路

 

 

标签:String,超大,pid,HTML5,pidRoot,new,上传,id,se
From: https://www.cnblogs.com/zyzzz/p/16938236.html

相关文章

  • 求超大文件上传方案( SpringBoot )
    ​ 这里只写后端的代码,基本的思想就是,前端将文件分片,然后每次访问上传接口的时候,向后端传入参数:当前为第几块文件,和分片总数下面直接贴代码吧,一些难懂的我大部分都加上......
  • PHP设计超级好用的文件上传处理类一 (37)
    <?phpclassFileUpload{private$filepath;//指定上传文件保存的路径private$allowtype=array('gif','jpg','png','jpeg');//充许上传文件......
  • vue大文件上传插件
    ​ 我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用。这次项目的需求:支持大文件的上传和续传,要求续传支持......
  • vue 上传插件
    ​ 关键部分前端用file.slice()分块前端用FileReader获取每一分块的md5值后端用MultipartFile接受分块文件后端用FileOutputStream拼装分块文件话不多说,直接上代码,......
  • 文件上传漏洞寻找思路(师承小迪)
    文件上传漏洞寻找思路(师承小迪)个人笔记第一步收集信息首先我们可以通过观察数据包,分析中间。主要关注的是,该网站用的是什么中间件(ApacheNginxIIS之类的),然后......
  • Python 中的 gRPC 文件上传和下载
    通过阅读本文,您将学习如何设置自己的gRPC客户端和服务器以使用Python上传/下载文件。供您参考,gRPC被称为远程过程调用,这是一种现代开放源代码,用于将设备、移动应......
  • 帝国CMS:批量上传Excel数据时候,无法将多图字段写入数据库?
    使用Excel批量上传插件的时候,根据插件规则,已经设置好了Excel表中的多图字段分段规则。但是上传后,发现无法在多图位置展现多图。查询插件的设置时发现都是正确的,前往多图功......
  • spring mvc环境之上传文件设置(五)
    springmvc环境之上传文件设置1.导入pom.xml依赖2.spring-mvc.xml配置bean3.测试 1.导入必要的依赖<!--上传组件包--><dependency><groupId>com......
  • java如何高效地读取一个超大文件?(四种方式分析对比)
    读取大文件的四种方式本地压缩了一个文件夹,大概500M左右。虽然不是很大但是,相对还可以。方法1:Guava读取Stringpath="G:\\java书籍及工具.zip";Files.readLines(new......
  • 文件图片上传
    [java]​​viewplain​​​​copy​​package  importimportimportimport  importimportimportimportimportimportimportimportimportimport  impor......