All Projects → gaoyuyue → Myuploader Backend

gaoyuyue / Myuploader Backend

Licence: apache-2.0
单文件上传,多文件上传,大文件上传,断点续传,文件秒传,图片上传

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Myuploader Backend

Ibase4j
Spring,SpringBoot 2.0,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,Spring-Session单点登录,Quartz分布式集群调度,Restful服务,QQ/微信登录,App token登录,微信/支付宝支付;日期转换、数据类型转换、序列化、汉字转拼音、身份证号码验证、数字转人民币、发送短信、发送邮件、加密解密、图片处理、excel导入导出、FTP/SFTP/fastDFS上传下载、二维码、XML读写、高精度计算、系统配置工具类等等。
Stars: ✭ 1,548 (+774.58%)
Mutual labels:  mybatis, spring-boot, spring, springmvc, maven
Nimrod
Nimrod - 基于 Spring Boot 构建 的 Java Web 平台企业级单体应用快速开发框架,适合中小型项目的应用和开发。所采用的技术栈包括 Spring Boot、Spring、Spring Web MVC、MyBatis、Thymeleaf 等,遵守阿里巴巴 Java 开发规约,帮助养成良好的编码习惯。整体采用 RBAC ( Role-Based Access Control ,基于角色的访问控制),具有严格的权限控制模块,支持系统与模块分离开发。最后希望这个项目能够对你有所帮助。Nimrod 开发交流群:547252502(QQ 群)
Stars: ✭ 125 (-29.38%)
Mutual labels:  mybatis, spring-boot, spring, maven
Seckill
基于SpringMVC,Spring,MyBatis实现的秒杀系统(参见慕课网,做了些改动)
Stars: ✭ 93 (-47.46%)
Mutual labels:  mybatis, spring, springmvc, maven
Hahu
参照知乎网做的一个简易版问答网站,后台采用Java语言,及Spring,SpringMVC,MyBatis等框架,模版引擎使用FreeMarker。数据库用到MySQL,Redis。
Stars: ✭ 408 (+130.51%)
Mutual labels:  mybatis, spring, springmvc, maven
Nguseckill
✨ 整合IDEA+Maven+SSM框架的高并发的商品秒杀项目
Stars: ✭ 373 (+110.73%)
Mutual labels:  mybatis, spring, springmvc, maven
Perfect Ssm
🍇更完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统(RESTful API+redis)
Stars: ✭ 606 (+242.37%)
Mutual labels:  mybatis, spring, springmvc, maven
Ssm Demo
🍌Spring+SpringMVC+Mybatis+easyUI实现简单的后台管理系统
Stars: ✭ 1,639 (+825.99%)
Mutual labels:  mybatis, spring, springmvc, maven
Spring Cloud Flycloud
🔥🔥🔥FlyClould 微服务实战项目框架,在该框架中,包括了用 Spring Cloud 构建微服务的一系列基本组件和框架,对于后台服务框架的搭建有很大的参考价值,大家可以参考甚至稍加修改可以直接应用于自己的实际的项目开发中,该项目没有采用Maven进行项目构建,Maven通过xml进行依赖管理,导致整个配置文件太过臃肿,另外灵活性也不是很强,所以我采用Gradle进行项目构建和依赖管理,在FlyTour项目中我们见证了Gradle的强大,通过简单的一些配置就可以轻松的实现组件化的功能。该项目共有11个Module工程。其中10个位微服务工程,这10个微服务工程构成了一个完整的微服务系统,微服务系统包含了8个基础服务,提供了一整套微服务治理功能,他们分别是配置中心module_c…
Stars: ✭ 1,514 (+755.37%)
Mutual labels:  spring-boot, spring, springmvc
Spring Cloud Build
Common build concerns, shared plugin configuration, etc. for Spring Cloud modules
Stars: ✭ 114 (-35.59%)
Mutual labels:  spring-boot, spring, maven
Priest
dubbo mybatis springboot base soa rest api framework with customer code generator
Stars: ✭ 160 (-9.6%)
Mutual labels:  mybatis, spring, springmvc
Supermarket
设计精良的网上商城系统,包括前端、后端、数据库、负载均衡、数据库缓存、分库分表、读写分离、全文检索、消息队列等,使用SpringCloud框架,基于Java开发。该项目可部署到服务器上,不断完善中……
Stars: ✭ 1,278 (+622.03%)
Mutual labels:  mybatis, spring, springmvc
Milkomeda
Spring extend componets which build from experience of bussiness, let developers to develop with Spring Boot as fast as possible.(基于Spring生态打造的一系列来自业务上的快速开发模块集合。)
Stars: ✭ 117 (-33.9%)
Mutual labels:  mybatis, spring-boot, spring
Shop
基于SpringMVC,Spring,Hibernate的网上商城。代码已久不维护...
Stars: ✭ 162 (-8.47%)
Mutual labels:  spring, springmvc, maven
Hsweb Payment
基于hsweb的开源聚合支付系统,多商户,多渠道,多配置.
Stars: ✭ 112 (-36.72%)
Mutual labels:  spring-boot, spring, maven
Mall
mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。
Stars: ✭ 54,797 (+30858.76%)
Mutual labels:  mybatis, spring-boot, spring
Superman
Superman是什么:构建Java 高级开发技术的知识体系,从基础不断打怪升级成为超人之路(更新中.......)
Stars: ✭ 106 (-40.11%)
Mutual labels:  mybatis, spring-boot, spring
Echo
🦄 开源社区系统:基于 SpringBoot + MyBatis + MySQL + Redis + Kafka + Elasticsearch + Spring Security + ... 并提供详细的开发文档和配套教程。包含帖子、评论、私信、系统通知、点赞、关注、搜索、用户设置、数据统计等模块。
Stars: ✭ 129 (-27.12%)
Mutual labels:  mybatis, spring, springmvc
Springboot Multiple Datasources
This is an example of automatically switching data sources for spring boot
Stars: ✭ 131 (-25.99%)
Mutual labels:  mybatis, spring-boot, spring
My Blog
🌴A simple & beautiful blogging system implemented with spring-boot & thymeleaf & mybatis My Blog 是由 SpringBoot + Mybatis + Thymeleaf 等技术实现的 Java 博客系统,页面美观、功能齐全、部署简单及完善的代码,一定会给使用者无与伦比的体验
Stars: ✭ 2,400 (+1255.93%)
Mutual labels:  mybatis, spring-boot, maven
Student Homework Management System
使用SSM+Shiro开发的学生作业管理系统。支持批量打包下载,QQ登陆等功能 生产版:
Stars: ✭ 79 (-55.37%)
Mutual labels:  mybatis, spring, springmvc

MyUploader-Backend

单文件上传,多文件上传,大文件上传,断点续传,文件秒传,图片上传

前端项目地址: https://github.com/gaoyuyue/MyUploader

简介

采用前后端分离的方式进行开发,实现了几种常用的文件上传功能。 前端采用 vue.js + plupload + element-ui 实现了文件在浏览器端的发送, 后端采用 spring boot + spring + spring mvc + mybatis 实现了文件在服务器端的接收和存储。

本项目为后端实现

效果图

演示地址: https://gaoyuyue.github.io/MyUploader

ps: 用git pages搭建的静态页面,只能演示前端功能

单文件上传

多文件上传

大文件上传

断点续传

文件秒传

图片上传

后端实现

未分块上传

采用MultipartFile接收上传文件并使用FileOutputStream写入文件

/**
 * 写入文件
 * @param target
 * @param src
 * @throws IOException
 */
public static void write(String target, InputStream src) throws IOException {
    OutputStream os = new FileOutputStream(target);
    byte[] buf = new byte[1024];
    int len;
    while (-1 != (len = src.read(buf))) {
        os.write(buf,0,len);
    }
    os.flush();
    os.close();
}

分块上传

采用MultipartFile接收上传文件的分块文件,上传参数包括:size:文件大小,chunk:分块号,chunks:总分块数

@PostMapping("/")
public void upload(String name,
                   String md5,
                   Long size,
                   Integer chunks,
                   Integer chunk,
                   MultipartFile file) throws IOException {
    if (chunks != null && chunks != 0) {
        fileService.uploadWithBlock(name, md5,size,chunks,chunk,file);
    } else {
        fileService.upload(name, md5,file);
    }
}

分块上传信息的存储

使用Map来存储分块的上传信息,key为文件唯一标识由前端发送这里采用文件MD5作为文件的唯一标识,value为自定义的静态内部类,其中name属性为文件在服务器端存储的随机文件名其在该文件的第一个分块上传到服务器时随机生成(UUID),boolean数组记录了分块的上传情况已上传置为true。

/**
 * 分块上传工具类
 */
public class UploadUtils {
    /**
     * 内部类记录分块上传文件信息
     */
    private static class Value {
        String name;
        boolean[] status;

        Value(int n) {
            this.name = generateFileName();
            this.status = new boolean[n];
        }
    }

    private static Map<String, Value> chunkMap = new HashMap<>();

    /**
     * 判断文件所有分块是否已上传
     * @param key
     * @return
     */
    public static boolean isUploaded(String key) {
        if (isExist(key)) {
            for (boolean b : chunkMap.get(key).status) {
                if (!b) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /**
     * 判断文件是否有分块已上传
     * @param key
     * @return
     */
    private static boolean isExist(String key) {
        return chunkMap.containsKey(key);
    }

    /**
     * 为文件添加上传分块记录
     * @param key
     * @param chunk
     */
    public static void addChunk(String key, int chunk) {
        chunkMap.get(key).status[chunk] = true;
    }

    /**
     * 从map中删除键为key的键值对
     * @param key
     */
    public static void removeKey(String key) {
        if (isExist(key)) {
            chunkMap.remove(key);
        }
    }

    /**
     * 获取随机生成的文件名
     * @param key
     * @param chunks
     * @return
     */
    public static String getFileName(String key, int chunks) {
        if (!isExist(key)) {
            synchronized (UploadUtils.class) {
                if (!isExist(key)) {
                    chunkMap.put(key, new Value(chunks));
                }
            }
        }
        return chunkMap.get(key).name;
    }
}

分块写入文件

使用RandomAccessFile随机读写文件,通过targetSize指定文件的大小,通过seek定位分块在文件中对应位置,通过write方法进行写入。

/**
 * 分块写入文件
 * @param target
 * @param targetSize
 * @param src
 * @param srcSize
 * @param chunks
 * @param chunk
 * @throws IOException
 */
public static void writeWithBlok(String target, Long targetSize, InputStream src, Long srcSize, Integer chunks, Integer chunk) throws IOException {
    RandomAccessFile randomAccessFile = new RandomAccessFile(target,"rw");
    randomAccessFile.setLength(targetSize);
    if (chunk == chunks - 1) {
        randomAccessFile.seek(targetSize - srcSize);
    } else {
        randomAccessFile.seek(chunk * srcSize);
    }
    byte[] buf = new byte[1024];
    int len;
    while (-1 != (len = src.read(buf))) {
        randomAccessFile.write(buf,0,len);
    }
    randomAccessFile.close();
}

分块上传逻辑

每次分块上传时首先获取对应文件在服务器端生成的随机文件名,如果不存在即在这之前还没有分块上传,则创建文件分块存储信息的键值对并存入map中,同时返回刚生成的随机文件名。然后将分块写入文件,同时将boolean数组中当前对应分块的位置置为true。最后判断该文件的所有分块是否全部上传,如果已全部上传完成则将文件信息写入数据库同时删除map中对应的键值对。

ps: 曾用文件夹存储上传分块,当分块全部上传完成时按顺序合并文件夹内所有分块,然后删除文件夹,后来发现RandomAccessFile果断弃坑。

/**
 * 分块上传文件
 * @param md5
 * @param size
 * @param chunks
 * @param chunk
 * @param file
 * @throws IOException
 */
public void uploadWithBlock(String name,
                            String md5,
                            Long size,
                            Integer chunks,
                            Integer chunk,
                            MultipartFile file) throws IOException {
    String fileName = getFileName(md5, chunks);
    FileUtils.writeWithBlok(UploadConfig.path + fileName, size, file.getInputStream(), file.getSize(), chunks, chunk);
    addChunk(md5,chunk);
    if (isUploaded(md5)) {
        removeKey(md5);
        fileDao.save(new File(name, md5,UploadConfig.path + fileName, new Date()));
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].