用 Spring Boot 纯手工打造私人云网盘!!!
前言
最近在做工作流的事情,正好有个需求,要添加一个附件上传的功能,曾找过不少上传插件,都不是特别满意。无意中发现一个很好用的开源web文件管理器插件 elfinder,功能比较完善,社区也很活跃,还方便二次开发。
环境搭建
软件 | 地址 |
---|---|
SpringBoot | https://spring.io/projects/spring-boot/ |
elFinder | https://studio-42.github.io/elFinder/ |
项目截图
周末抽时间做了一个简单的案例,希望对大家有所帮助,下面是简单的项目截图。
项目功能
在线新建目录、文件、附件上传、下载、预览、在线打包,图片在线裁剪、编辑,实现列表试图、图标视图等等一些列功能。
项目配置
项目基于 SpringBoot 注解配置实现,在第三方插件进行二次开发。
application.properties 配置:
# 执行类,内部调用,实现前端相关功能
file-manager.command=com.itstyle.cloud.common.elfinder.command
file-manager.thumbnail.width=80
file-manager.volumes[0].Node=
file-manager.volumes[0].source=fileSystem
file-manager.volumes[0].alias=file
# 文件存放目录,可以自定义
file-manager.volumes[0].path=D:/cloudFile
file-manager.volumes[0]._default=true
file-manager.volumes[0].locale=
file-manager.volumes[0].constraint.locked=false
file-manager.volumes[0].constraint.readable=true
file-manager.volumes[0].constraint.writable=true
ElfinderConfiguration 读取配置:
@Component
@ConfigurationProperties(prefix="file-manager") //接收application.properties中的file-manager下面的属性
public class ElfinderConfiguration {private Thumbnail thumbnail;private String command;private List<Node> volumes;private Long maxUploadSize = -1L;//省略部分代码}
elfinderStorageFactory 初始化 基础Bean:
@Configuration
public class ElFinderConfig {@Autowiredprivate ElfinderConfiguration elfinderConfiguration;@Bean(name = "commandFactory")public CommandFactory getCommandFactory() {CommandFactory commandFactory = new CommandFactory();commandFactory.setClassNamePattern(elfinderConfiguration.getCommand()+".%sCommand");return commandFactory;}@Bean(name = "elfinderStorageFactory")public ElfinderStorageFactory getElfinderStorageFactory() {DefaultElfinderStorageFactory elfinderStorageFactory = new DefaultElfinderStorageFactory();elfinderStorageFactory.setElfinderStorage(getElfinderStorage());return elfinderStorageFactory;}@Bean(name = "elfinderStorage")public ElfinderStorage getElfinderStorage() {DefaultElfinderStorage defaultElfinderStorage = new DefaultElfinderStorage();// creates thumbnailDefaultThumbnailWidth defaultThumbnailWidth = new DefaultThumbnailWidth();defaultThumbnailWidth.setThumbnailWidth(elfinderConfiguration.getThumbnail().getWidth().intValue());// creates volumes, volumeIds, volumeLocale and volumeSecuritiesCharacter defaultVolumeId = 'A';List<Node> elfinderConfigurationVolumes = elfinderConfiguration.getVolumes();List<Volume> elfinderVolumes = new ArrayList<>(elfinderConfigurationVolumes.size());Map<Volume, String> elfinderVolumeIds = new HashMap<>(elfinderConfigurationVolumes.size());Map<Volume, Locale> elfinderVolumeLocales = new HashMap<>(elfinderConfigurationVolumes.size());List<VolumeSecurity> elfinderVolumeSecurities = new ArrayList<>();// creates volumesfor (Node elfinderConfigurationVolume : elfinderConfigurationVolumes) {final String alias = elfinderConfigurationVolume.getAlias();final String path = elfinderConfigurationVolume.getPath();final String source = elfinderConfigurationVolume.getSource();final String locale = elfinderConfigurationVolume.getLocale();final Boolean isLocked = elfinderConfigurationVolume.getConstraint().isLocked();final Boolean isReadable = elfinderConfigurationVolume.getConstraint().isReadable();final Boolean isWritable = elfinderConfigurationVolume.getConstraint().isWritable();// creates new volumeVolume volume = VolumeSources.of(source).newInstance(alias, path);elfinderVolumes.add(volume);elfinderVolumeIds.put(volume, Character.toString(defaultVolumeId));elfinderVolumeLocales.put(volume, LocaleUtils.toLocale(locale));// creates security constraintSecurityConstraint securityConstraint = new SecurityConstraint();securityConstraint.setLocked(isLocked);securityConstraint.setReadable(isReadable);securityConstraint.setWritable(isWritable);// creates volume pattern and volume securityfinal String volumePattern = Character.toString(defaultVolumeId) + ElFinderConstants.ELFINDER_VOLUME_SERCURITY_REGEX;elfinderVolumeSecurities.add(new DefaultVolumeSecurity(volumePattern, securityConstraint));// prepare next volumeId characterdefaultVolumeId++;}defaultElfinderStorage.setThumbnailWidth(defaultThumbnailWidth);defaultElfinderStorage.setVolumes(elfinderVolumes);defaultElfinderStorage.setVolumeIds(elfinderVolumeIds);defaultElfinderStorage.setVolumeLocales(elfinderVolumeLocales);defaultElfinderStorage.setVolumeSecurities(elfinderVolumeSecurities);return defaultElfinderStorage;}
}
CloudDiskController 控制层实现:
@Controller
@RequestMapping("elfinder/connector")
public class CloudDiskController {private static final Logger logger = LoggerFactory.getLogger(CloudDiskController.class);public static final String OPEN_STREAM = "openStream";public static final String GET_PARAMETER = "getParameter";@Resource(name = "commandFactory")private ElfinderCommandFactory elfinderCommandFactory;@Resource(name = "elfinderStorageFactory")private ElfinderStorageFactory elfinderStorageFactory;@RequestMappingpublic void connector(HttpServletRequest request, final HttpServletResponse response) throws IOException {try {response.setCharacterEncoding("UTF-8");request = processMultipartContent(request);}catch (Exception e) {throw new IOException(e.getMessage());}String cmd = request.getParameter(ElFinderConstants.ELFINDER_PARAMETER_COMMAND);ElfinderCommand elfinderCommand = elfinderCommandFactory.get(cmd);try {final HttpServletRequest protectedRequest = request;elfinderCommand.execute(new ElfinderContext() {@Overridepublic ElfinderStorageFactory getVolumeSourceFactory() {return elfinderStorageFactory;}@Overridepublic HttpServletRequest getRequest() {return protectedRequest;}@Overridepublic HttpServletResponse getResponse() {return response;}});}catch (Exception e) {logger.error("Unknown error", e);}}//省略部分代码
}
最后,前端页面引入:
// ... 省略,具体看源码。微信文章限制长度。
小结
总体来说个人使用还是非常不错的,当然对于一些成熟的网盘系统还是有一些差距。
源码:
https://gitee.com/52itstyle/spring-boot-CloudDisk
用 Spring Boot 纯手工打造私人云网盘!!!相关推荐
- SpringBoot 2.x 纯手工打造私人网盘项目
点击▲关注 "爪哇笔记" 给公众号标星置顶 更多摄影技巧 第一时间直达 简介 基于 SpringBoot2.x + elFinder 搭建的私有云盘服务,功能堪比某度网盘,丰富 ...
- 原创:纯手工打造CSS像素画--笨笨熊系列图标
纯手工打造CSS像素画--笨笨熊系列图标 作者:冰极峰 转载请注明出处 在cssplay网站看到有一组CSS像素画,于是也想摩仿一下,于是在网络上找到一组头像图标,看其结构比较简单,就拿它开刀吧!先看 ...
- 广工学生“纯手工”打造赛车 将出征F1赛道
转播到腾讯微博 一辆红银色流线型方程式赛车昨日亮相广东工业大学图书馆广场.这辆赛车为该校二十余名学生"纯手工"打造,本月将登陆上海国际赛车场.南都记者邹卫摄 南都讯 记者刘黎霞 实 ...
- html格子像素画,HTML_纯手工打造CSS像素画,在cssplay网站看到有一组CSS像素 - phpStudy...
纯手工打造CSS像素画 在cssplay网站看到有一组CSS像素画,于是也想摩仿一下,于是在网络上找到一组头像图标,看其结构比较简单,就拿它开刀吧!先看看预览图 图一 基本原理: 没有什么技术含量,主 ...
- IOS学习之道:使用UIButton纯手工打造的黑白快小游戏.
由于代码量比较多,有兴趣的同学可以去我的资源页进行下载. http://download.csdn.net/detail/tx874828503/8637445 // // RootViewContr ...
- 后渗透篇:纯手工打造服务器自解压shift后门【详细演示】
当你的才华 还撑不起你的野心时 那你就应该静下心来学习 目录 纯手工打造服务器自解压shift后门 0x01 介绍 0x02 实例演示 纯手工打造服务器自解压shift后门 0x01 介绍 很多时候我 ...
- 消防管件做的机器人图片_报废消防器材变身“机器人” 由消防官兵纯手工打造(图)...
原标题:报废消防器材变身"机器人" 由消防官兵纯手工打造(图) 由报废的消防零配件组成的机器人模型. 厦门网讯 (厦门日报记者林路然通讯员阙凤芳曾德猛)远看好似变形金刚,凑近还会说 ...
- 带计算机功能的私有云,不怕网盘关闭!老司机教你用PC搭建私人云网盘
[PConline 技巧]又有云网盘服务倒闭了!之前是金山华为等等一大票,现在连360网盘都关掉了!360啊华为啊都够大牌了吧?你还敢信誓旦旦说百度腾讯它们的网盘就一定会永远开下去?这年头,似乎哪个网 ...
- 计算机云共享盘,搭建私人云网盘:局域网访问共享数据
搭建私人云网盘:局域网访问私人云的共享数据 作为一个云网盘,首先当然是得能访问里面的数据.我们首先来看局域网环境下的情况. 很多朋友都在使用路由器,家里有几部电脑或者手机都连接在同一个路由器中.在这种 ...
最新文章
- Leetcode 38.外观数列 (每日一题 20210702)
- 模板:网络流(Dinic算法)
- math.sqrt 有问题_JavaScript中带有示例的Math.SQRT2属性
- 显示2位小数 python3_Python2和Python3的区别
- php属性未定义,PHP-警告-未定义的属性:stdClass-修复?
- Spring.NET学习笔记15——AOP的配置(基础篇) Level 200
- 【Linux】查看日志文件
- 【UML】协作图Collaboration diagram(交互图)(转)
- Form.close与Application.Exit()的区别
- 如何使用 Apple Watch 拨打电话?
- 【优化布局】基于matlab遗传算法求解带出入点的车间布局优化问题【含Matlab源码 011期】
- javascript调试 debugger 代码调试
- 【批处理】肉鸡扫描脚本
- js动态显示实时时间
- 洛谷1260 工程规划
- 软件测试工程师的自我认识和定位!!
- 精准关键词获取-行业搜索词分析
- ICLR 2022最佳论文解读
- 【论文阅读第一期】Goods:Organizing Google’s Datasets总结
- 【Android实战】保存QQ账号与密码