Skip to content

Commit

Permalink
Merge pull request #122 from 1171736840/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
1171736840 authored Oct 17, 2023
2 parents 0fe4609 + d720ba7 commit a99d15f
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 13 deletions.
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3 align="center">
<img src="https://x-file-storage.xuyanwu.cn/assets/logo.svg" height="200px" alt="logo"/><br />
<span>原名 X Spring File Storage 现已捐赠至 <a target="_blank" href="https://dromara.org/zh">dromara</a> 开源组织<span>
<span>原名 X Spring File Storage 现已捐赠至 <a target="_blank" href="https://dromara.org/zh">dromara</a> 开源组织</span>
</h3>

<p align="center">
Expand Down Expand Up @@ -196,9 +196,41 @@ public class FileDetailController {
}
```

#### ⚠️重要提示
#### 🎨其它操作

如果想使用删除、下载等功能,请阅读 [保存上传记录](https://x-file-storage.xuyanwu.cn/#/基础功能?id=保存上传记录) 章节
```java
//手动构造文件信息,可用于其它操作
FileInfo fileInfo = new FileInfo()
.setPlatform("huawei-obs-1")
.setBasePath("test/")
.setPath("aa/")
.setFilename("image.png")
.setThFilename("image.png.min.jpg");
//文件是否存在
boolean exists = fileStorageService.exists(fileInfo);
//下载
byte[] bytes = fileStorageService.download(fileInfo).bytes();
//删除
fileStorageService.delete(fileInfo);
//其它更多操作
```

如果将文件记录保存到数据库中,还可以更方便的根据 URL 进行操作了,详情请阅读 [保存上传记录](https://x-file-storage.xuyanwu.cn/#/基础功能?id=保存上传记录) 章节

```java
//直接从数据库中获取 FileInfo 对象,更加方便执行其它操作
FileInfo fileInfo = fileStorageService.getFileInfoByUrl("https://abc.def.com/test/aa/image.png");
//文件是否存在
boolean exists = fileStorageService.exists("https://abc.def.com/test/aa/image.png");
//下载
byte[] bytes = fileStorageService.download("https://abc.def.com/test/aa/image.png").bytes();
//删除
fileStorageService.delete("https://abc.def.com/test/aa/image.png");
//其它更多操作
```

-------

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3 align="center">
<img src="https://x-file-storage.xuyanwu.cn/assets/logo.svg" height="200px" alt="logo"/><br />
<span>原名 X Spring File Storage 现已捐赠至 <a target="_blank" href="https://dromara.org/zh">dromara</a> 开源组织<span>
<span>原名 X Spring File Storage 现已捐赠至 <a target="_blank" href="https://dromara.org/zh">dromara</a> 开源组织</span>
</h3>

<p align="center">
Expand Down
2 changes: 1 addition & 1 deletion docs/基础功能.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fileStorageService.of(file).setProgressMonitor(new ProgressListener() {

## 保存上传记录

如果还想使用除了保存文件之外的其它功能,例如删除、下载文件,还需要实现 `FileRecorder` 这个接口,把文件信息保存到数据库中。
可以实现 `FileRecorder` 这个接口,把文件信息保存到数据库中。

```java
/**
Expand Down
40 changes: 36 additions & 4 deletions docs/快速入门.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,7 @@ public class SpringFileStorageTestApplication {

## 开始使用

到此为止就可以使用上传功能了 ,如果想使用删除、下载等功能,请阅读 [保存上传记录](基础功能?id=保存上传记录) 章节

### 上传
支持 File、MultipartFile、byte[]、InputStream、URL、URI、String、HttpServletRequest,大文件会自动分片上传。如果想支持更多方式,请阅读 [文件适配器](文件适配器) 章节


Expand Down Expand Up @@ -552,5 +551,38 @@ public class FileDetailController {
}
```

> [!WARNING|label:重要提示:]
> 如果想使用删除、下载等功能,请阅读 [保存上传记录](基础功能?id=保存上传记录) 章节
### 其它操作

```java
//手动构造文件信息,可用于其它操作
FileInfo fileInfo = new FileInfo()
.setPlatform("huawei-obs-1")
.setBasePath("test/")
.setPath("aa/")
.setFilename("image.png")
.setThFilename("image.png.min.jpg");
//文件是否存在
boolean exists = fileStorageService.exists(fileInfo);
//下载
byte[] bytes = fileStorageService.download(fileInfo).bytes();
//删除
fileStorageService.delete(fileInfo);
//其它更多操作
```

如果将文件记录保存到数据库中,还可以更方便的根据 URL 进行操作了,详情请阅读 [保存上传记录](基础功能?id=保存上传记录) 章节

```java
//直接从数据库中获取 FileInfo 对象,更加方便执行其它操作
FileInfo fileInfo = fileStorageService.getFileInfoByUrl("https://abc.def.com/test/aa/image.png");
//文件是否存在
boolean exists = fileStorageService.exists("https://abc.def.com/test/aa/image.png");
//下载
byte[] bytes = fileStorageService.download("https://abc.def.com/test/aa/image.png").bytes();
//删除
fileStorageService.delete("https://abc.def.com/test/aa/image.png");
//其它更多操作
```
3 changes: 2 additions & 1 deletion docs/更新记录.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
-------

## 📦2.0.0 :id=_200
2023-09-21
2023-10-17
- 更改项目名、更改包名、优化项目结构
- 新增直接读取 HttpServletRequest 的流进行上传,文件不落盘,速度更快
- 新增支持 Metadata 元数据
- 优化 ACL 异常处理
- 优化文件删除逻辑
- 修复 Amazon S3 上传文件偶现 ResetException 问题
- 捐赠至 [dromara](https://dromara.org/zh) 开源社区

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import cn.hutool.core.lang.Dict;
import lombok.Data;
import lombok.experimental.Accessors;
import org.dromara.x.file.storage.core.constant.Constant;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

@Data
@Accessors(chain = true)
public class FileInfo implements Serializable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public FileInfo getByUrl(String url) {

@Override
public boolean delete(String url) {
throw new FileStorageRuntimeException("尚未实现 FileRecorder 接口,暂时无法使用此功能,参考文档:https://x-file-storage.xuyanwu.cn/#/%E5%9F%BA%E7%A1%80%E5%8A%9F%E8%83%BD?id=%E4%BF%9D%E5%AD%98%E4%B8%8A%E4%BC%A0%E8%AE%B0%E5%BD%95");
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public void download() {
public void invoke() {
FileStorage fileStorage = fileStorageService.getFileStorage();
Object[] args = new Object[]{fileStorage.getPlatform()};
Object exists = fileStorageService.invoke(fileStorage,"setPlatform",args);
log.info("通过反射调用存储平台的方法(文件是否存在)成功,结果:{}",exists);
Object result = fileStorageService.invoke(fileStorage,"setPlatform",args);
log.info("通过反射调用存储平台的方法(文件是否存在)成功,结果:{}",result);
}

}

0 comments on commit a99d15f

Please sign in to comment.