package com.example.demo.storage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;
import org.springframework.util.FileSystemUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.stream.Stream;
@Service
public class FileSystemStorageService implements StorageService {
private final Path rootLocation;
@Autowired
public FileSystemStorageService(StorageProperties properties) {
this.rootLocation = Paths.get(properties.getLocation());
}
@Override
public void store(MultipartFile file) {
try {
if (file.isEmpty()) {
throw new StorageException("Failed to store empty file.");
}
Path destinationFile = this.rootLocation.resolve(
Paths.get(file.getOriginalFilename()))
.normalize().toAbsolutePath();
if (!destinationFile.getParent().equals(this.rootLocation.toAbsolutePath())) {
// This is a security check
throw new StorageException("Cannot store file outside current directory.");
}
try (InputStream inputStream = file.getInputStream()) {
Files.copy(inputStream, destinationFile,
StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
throw new StorageException("Failed to store file.", e);
}
}
@Override
public Stream<Path> loadAll() {
try {
return Files.walk(this.rootLocation, 1)
.filter(path -> !path.equals(this.rootLocation))
.map(this.rootLocation::relativize);
} catch (IOException e) {
throw new StorageException("Failed to read stored files", e);
}
}
@Override
public Path load(String filename) {
return rootLocation.resolve(filename);
}
@Override
public Resource loadAsResource(String filename) {
try {
Path file = load(filename);
Resource resource = new UrlResource(file.toUri());
if (resource.exists() || resource.isReadable()) {
return resource;
} else {
throw new StorageFileNotFoundException(
"Could not read file: " + filename);
}
} catch (MalformedURLException e) {
throw new StorageFileNotFoundException("Could not read file: " + filename, e);
}
}
@Override
public void deleteAll() {
FileSystemUtils.deleteRecursively(rootLocation.toFile());
}
@Override
public void init() {
try {
Files.createDirectories(rootLocation);
} catch (IOException e) {
throw new StorageException("Could not initialize storage", e);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于springboot+vue的保险信息网站源码数据库.zip
共442个文件
js:94个
jpg:69个
css:57个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 110 浏览量
2023-06-21
14:16:58
上传
评论
收藏 13.84MB ZIP 举报
温馨提示
源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经
资源推荐
资源详情
资源评论
收起资源包目录
基于springboot+vue的保险信息网站源码数据库.zip (442个子文件)
.browserslistrc 33B
User.class 8KB
FileSystemStorageService.class 6KB
FileUploadController.class 5KB
Insurance.class 5KB
Recommend.class 5KB
Comment.class 4KB
News.class 4KB
UserRepository.class 2KB
RecommendRepository.class 2KB
ExposeEntityIdRestRepositoryRestConfigurer.class 1KB
InsuranceRepository.class 1KB
CommentRepository.class 1002B
DemoApplication.class 806B
StorageProperties.class 720B
StorageFileNotFoundException.class 667B
StorageException.class 616B
StorageService.class 580B
NewsRepository.class 528B
chunk-vendors.67018e50.css 228KB
chunk-vendors.67018e50.css 228KB
index.css 228KB
app.711dc16d.css 209KB
app.711dc16d.css 209KB
chunk-vendors.259bd0ec.css 204KB
chunk-vendors.259bd0ec.css 204KB
bootstrap.css 183KB
bootstrap.min.css 138KB
all.css 62KB
editor.9be2e4d6.css 37KB
editor.9be2e4d6.css 37KB
style.css 36KB
bootstrap-grid.css 34KB
bootstrap-grid.min.css 24KB
jquery.fancybox.min.css 14KB
bootstrap-reboot.css 5KB
icon.649ff013.css 5KB
icon.649ff013.css 5KB
upload.5df925fb.css 4KB
upload.5df925fb.css 4KB
bootstrap-reboot.min.css 4KB
home.cce0acf9.css 3KB
home.cce0acf9.css 3KB
main.css 3KB
app.f0308011.css 2KB
app.f0308011.css 2KB
markdown.360c635a.css 2KB
markdown.360c635a.css 2KB
dashboard.1dd31924.css 2KB
dashboard.1dd31924.css 2KB
owl.carousel.min.css 1KB
drag.0d86e883.css 1KB
drag.0d86e883.css 1KB
403.eaddfc90.css 724B
404.dc58a6fc.css 724B
403.eaddfc90.css 724B
404.dc58a6fc.css 724B
login.17c453b1.css 691B
login.17c453b1.css 691B
color-green.css 687B
color-dark.css 438B
table.3d7cc353.css 361B
table.3d7cc353.css 361B
chunk-7bb20528.6e71b5ee.css 335B
chunk-405a902d.9320ad64.css 335B
chunk-7bb20528.6e71b5ee.css 335B
chunk-405a902d.9320ad64.css 335B
chart.531d6ca1.css 231B
chart.531d6ca1.css 231B
permission.37db8fc8.css 162B
permission.37db8fc8.css 162B
i18n.8a49cc5f.css 115B
i18n.8a49cc5f.css 115B
icon.css 89B
tabs.acfac5ad.css 58B
tabs.acfac5ad.css 58B
fa-solid-900.70e65a7d.eot 176KB
fa-solid-900.eot 176KB
fa-solid-900.70e65a7d.eot 176KB
fa-brands-400.9b6c8da3.eot 116KB
fa-brands-400.eot 116KB
fa-brands-400.9b6c8da3.eot 116KB
fa-regular-400.7422060c.eot 40KB
fa-regular-400.eot 40KB
fa-regular-400.7422060c.eot 40KB
fontello.e73a0647.eot 15KB
fontello.e73a0647.eot 15KB
.gitignore 395B
.gitignore 238B
.gitignore 231B
.gitignore 0B
admin.html 3KB
admin.html 3KB
index.html 2KB
index.html 2KB
index.html 602B
index.html 593B
FileSystemStorageService.java 3KB
FileUploadController.java 2KB
User.java 1KB
共 442 条
- 1
- 2
- 3
- 4
- 5
资源评论
老歪不歪
- 粉丝: 31
- 资源: 4039
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 实践项目-图书馆管理系统(C#.NET)
- 10Eclipse项目源码.jpg
- 大屏可视化数据课程项目
- Maven 快速入门指南:安装和配置方法详解
- STM32物信息通过MQTT协议上传云平台
- STM32物信息通过MQTT协议上传云平台
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本122.0.6260.0)
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本122.0.6259.0)
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本122.0.6258.0)
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本122.0.6257.0)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功