Skip to content

Commit

Permalink
Merge pull request #198 from 1171736840/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
1171736840 authored Jan 11, 2024
2 parents 914f13f + 0531c1a commit 17e354c
Show file tree
Hide file tree
Showing 16 changed files with 802 additions and 432 deletions.
2 changes: 1 addition & 1 deletion docs/Metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 使用

可以在上传时传入 Metadata 和 UserMetadata ,目前仅 华为云 OBS、阿里云 OSS、腾讯云 COS、百度云 BOS、七牛云 Kodo、又拍云 USS、MinIO、Amazon S3、GoogleCloud Storage、FastDFS、Azure Blob 平台支持
可以在上传时传入 Metadata 和 UserMetadata ,目前仅 华为云 OBS、阿里云 OSS、腾讯云 COS、百度云 BOS、七牛云 Kodo、又拍云 USS、MinIO、Amazon S3、GoogleCloud Storage、FastDFS、Azure Blob Storage 平台支持

```java
//判断是否支持 Metadata
Expand Down
25 changes: 24 additions & 1 deletion docs/acl.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ACL 访问控制列表

也叫预定义访问策略,目前仅 华为云 OBS、阿里云 OSS、腾讯云 COS、百度云 BOS、Amazon S3、GoogleCloud Storage 平台支持
也叫预定义访问策略,目前仅 华为云 OBS、阿里云 OSS、腾讯云 COS、百度云 BOS、Amazon S3、GoogleCloud Storage、Azure Blob Storage 平台支持

Azure Blob Storage 即使将文件的 ACL 设置为 公共读`PUBLIC_READ` ,上传成功后的 `url` 也无法通过浏览器直接公开访问 ,详情阅读 [兼容性说明-AzureBlobStorage](存储平台?id=OCI_AzureBlobStorage) 章节

## 设置 ACL

Expand Down Expand Up @@ -109,6 +111,27 @@ fileStorageService.of(file).setFileAcl(Arrays.asList(acl2,acl3)).upload();

```

#### **Azure Blob Storage**

ACL 参考文档:https://learn.microsoft.com/zh-cn/azure/storage/blobs/data-lake-storage-access-control <br>
SDK 参考文档:https://learn.microsoft.com/zh-cn/azure/storage/blobs/data-lake-storage-acl-java#set-acls

```java
//第一种:使用官方 SDK 中的 PathPermissions 对象
PathPermissions permissions = new PathPermissions()
.setGroup(new RolePermissions().setReadPermission(true))
.setOwner(new RolePermissions().setReadPermission(true).setWritePermission(true));
fileStorageService.of(file).setFileAcl(permissions).upload();

//第二种,使用官方 SDK 中的 PathAccessControlEntry 对象
PathAccessControlEntry acl = PathAccessControlEntry.parse("user::rw-");
fileStorageService.of(file).setFileAcl(acl).upload();

//第二种可以一次设置多个
List<PathAccessControlEntry> acl = PathAccessControlEntry.parseList("user::rw-,group::r--,other::---");
fileStorageService.of(file).setFileAcl(acl).upload();
```

<!-- tabs:end -->

> [!WARNING|label:重要提示:]
Expand Down
62 changes: 45 additions & 17 deletions docs/存储平台.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
> 1. 在使用复制功能时,如果同存储平台复制不支持,则会自动使用跨存储平台复制,内部是通过先下载再上传实现的,所有存储平台都支持,详情请阅读 [复制](基础功能?id=复制) 章节
> 2. 在使用移动(重命名)功能时,如果同存储平台移动(重命名)不支持,则会自动使用跨存储平台移动(重命名),内部是通过先复制再删除源文件实现的,所有存储平台都支持,详情请阅读 [移动(重命名)](基础功能?id=移动(重命名)) 章节
| 存储平台 | 上传 | 下载 | 删除 | 手动分片上传 | 预签名 URL | 同存储平台复制 | 同存储平台移动(重命名) | ACL 访问控制列表 | Metadata 元数据 | 兼容性说明 |
|---------------------|----|----|----|--------|---------|---------|--------------|------------|--------------|---------------------------|
| 本地 | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ ||| |
| FTP | ✔️ | ✔️ | ✔️ |||| ✔️ ||| |
| SFTP | ✔️ | ✔️ | ✔️ |||| ✔️ ||| |
| WebDAV | ✔️ | ✔️ | ✔️ ||| ✔️ | ✔️ ||| |
| Amazon S3 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| MinIO | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ ||| ✔️ | |
| 阿里云 OSS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| 华为云 OBS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| 腾讯云 COS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| 百度云 BOS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| 又拍云 USS | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ || ✔️ | |
| 七牛云 Kodo | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | |
| GoogleCloud Storage | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ || ✔️ | ✔️ | |
| FastDFS | ✔️ | ✔️ | ✔️ |||||| ✔️ | [查看](存储平台?id=OCI_FastDFS) |
| Azure Blob | ✔️ | ✔️ | ✔️ | | ✔️ | ✔️ || | ✔️ | |
| 存储平台 | 上传 | 下载 | 删除 | 手动分片上传 | 预签名 URL | 同存储平台复制 | 同存储平台移动(重命名) | ACL 访问控制列表 | Metadata 元数据 | 兼容性说明 |
|---------------------|----|----|----|--------|---------|---------|--------------|------------|--------------|------------------------------------|
| 本地 | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ ||| |
| FTP | ✔️ | ✔️ | ✔️ |||| ✔️ ||| |
| SFTP | ✔️ | ✔️ | ✔️ |||| ✔️ ||| |
| WebDAV | ✔️ | ✔️ | ✔️ ||| ✔️ | ✔️ ||| |
| Amazon S3 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| MinIO | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ ||| ✔️ | |
| 阿里云 OSS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| 华为云 OBS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| 腾讯云 COS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| 百度云 BOS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | |
| 又拍云 USS | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ || ✔️ | |
| 七牛云 Kodo | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | |
| GoogleCloud Storage | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ || ✔️ | ✔️ | |
| FastDFS | ✔️ | ✔️ | ✔️ |||||| ✔️ | [查看](存储平台?id=OCI_FastDFS) |
| Azure Blob Storage | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ || ✔️ | ✔️ | [查看](存储平台?id=OCI_AzureBlobStorage) |

对于兼容 Amazon S3 的存储平台,直接将配置写在 Amazon S3 中即可,具体兼容性见下图。

Expand Down Expand Up @@ -973,3 +973,31 @@ FileInfo(
thUrl=http://192.168.1.121:8088/group1/M00/00/01/rBEgUGWd8C2AZfguAABy-xvVi1c065.jpg.min.jpg
)
```

### Azure Blob Storage :id=OCI_AzureBlobStorage

Azure Blob Storage 主要要注意的地方就是 ACL (访问控制列表)功能,无法做到像 Amazon S3 那样针对单个文件设置公开访问,
即使将文件的 ACL 设置为 公共读`PUBLIC_READ` ,上传成功后的 `url` 也无法通过浏览器直接公开访问,但实际上已经设置成功了,
可以在 AzureBlob 控制台看到,现有有以下解决办法可以参考:

**方式一**

可以使用 [预签名 URL](预签名URL?id=预签名-url) 获取临时授权访问代替

**方式二**

将数据湖和容器同时开启公开访问,这样<span style="color:red">所有文件</span>就都可以公开访问了(无法针对单个文件设置)<br>
数据湖:AzureBlob控制台-设置-配置-允许Blob匿名访问-勾选已启用<br>
容器:AzureBlob控制台-数据存储-容器-勾选对应容器-点击顶部匿名访问级别-选择第二个Blob(仅匿名读取访问blob)

**方式三**

`domain` 参数设置为自己的服务器地址,在服务器上编写对应接口,这样上传文件后的 `url` 就是后台地址了,当访问这个 `url` 时,
后台根据 `url` 解析出文件信息或从数据中查询出文件信息,校验是否有权限访问,如果有则再使用 [预签名 URL](预签名URL?id=预签名-url) 获取临时授权访问地址,
最后发起重定向到此地址即可。我觉得这可能是兼容性最好的方式了,只要编写这一个重定向接口,所有操作同其它存储平台一样

> [!TIP|label:说明:]
> 也许原本就可以做到这个功能,只是我的操作有问题,如果你对此有了解,可以在 [Gitee](https://gitee.com/dromara/x-file-storage/issues/new)[GitHub](https://gitee.com/dromara/x-file-storage/issues/new) 提交 Issues 进行讨论,也可以点击添加
<a target="_blank" href='https://jq.qq.com/?_wv=1027&k=eGfeNqka'>
<img src='https://img.shields.io/badge/QQ%E7%BE%A4-515706495-orange' alt='515706495' />
</a> 一起交流
12 changes: 9 additions & 3 deletions docs/快速入门.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,20 @@
</dependency>
```

#### **Azure Blob**
#### **Azure Blob Storage**

```xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.23.1</version>
</dependency>
<!-- Azure File Data Lake 用于处理 ACL,不使用的情况下可以不引入 -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-file-datalake</artifactId>
<version>12.18.1</version>
</dependency>
```

#### **本地**
Expand Down Expand Up @@ -431,9 +437,9 @@ fastdfs:

更多参数请参考 `org.dromara.x.file.storage.spring.SpringFileStorageProperties.SpringFastDfsConfig`

#### **Azure Blob**
#### **Azure Blob Storage**

注意在 Azure 控制台创建存储帐户时要勾选“启用分层命名空间”功能
注意在 Azure 控制台创建存储帐户时要勾选“启用分层命名空间”功能,上传成功后的 `url` 默认是无法公开访问的,详情阅读 [兼容性说明-AzureBlobStorage](存储平台?id=OCI_AzureBlobStorage) 章节

```yaml
azure-blob:
Expand Down
2 changes: 1 addition & 1 deletion docs/预签名URL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## 生成

目前仅 华为云 OBS、阿里云 OSS、七牛云 Kodo、腾讯云 COS、百度云 BOS、MinIO、Amazon S3、GoogleCloud Storage、Azure Blob 平台支持
目前仅 华为云 OBS、阿里云 OSS、七牛云 Kodo、腾讯云 COS、百度云 BOS、MinIO、Amazon S3、GoogleCloud Storage、Azure Blob Storage 平台支持

```java
//判断对应的存储平台是否支持预签名 URL
Expand Down
22 changes: 18 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
<role>Contrib</role>
</roles>
</developer>
<developer>
<id>dongfeng</id>
<name>dongfeng</name>
<email>dongfeng@51ddi.com</email>
<roles>
<role>Contrib</role>
</roles>
</developer>
</developers>

<modules>
Expand Down Expand Up @@ -92,7 +100,8 @@
<tika-core.version>2.4.1</tika-core.version>
<upyun-java-sdk.version>4.2.3</upyun-java-sdk.version>
<fastdfs-client-java.version>1.30-20230328</fastdfs-client-java.version>
<azure-storage-blob-sdk.version>12.23.1</azure-storage-blob-sdk.version>
<azure-storage-blob.version>12.23.1</azure-storage-blob.version>
<azure-storage-file-datalake.version>12.18.1</azure-storage-file-datalake.version>
<!--endregion-->

<!--region Maven Plugins-->
Expand Down Expand Up @@ -259,13 +268,18 @@
<artifactId>fastdfs-client-java</artifactId>
<version>${fastdfs-client-java.version}</version>
</dependency>
<!-- 微软 Azure blob-->
<!-- Azure Blob -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>${azure-storage-blob-sdk.version}</version>
<version>${azure-storage-blob.version}</version>
</dependency>
<!-- Azure File Data Lake 用于处理 ACL -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-file-datalake</artifactId>
<version>${azure-storage-file-datalake.version}</version>
</dependency>
<!--endregion-->
</dependencies>
</dependencyManagement>

Expand Down
10 changes: 9 additions & 1 deletion x-file-storage-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,21 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- 微软 Azure blob-->
<!-- Azure Blob -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- Azure File Data Lake 用于处理 ACL -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-file-datalake</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<!--糊涂工具类核心-->
<dependency>
<groupId>cn.hutool</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public class FileStorageProperties {
private List<? extends FastDfsConfig> fastdfs = new ArrayList<>();

/**
* 微软Azure Blob
* Azure Blob Storage
*/
private List<? extends AzureBlobStorageConfig> azureBlob = new ArrayList<>();

Expand Down Expand Up @@ -971,6 +971,11 @@ public static class AzureBlobStorageConfig extends BaseConfig {
*/
private String basePath = "";

/**
* 默认的 ACL,详情 {@link Constant.AzureBlobStorageACL}
*/
private String defaultAcl;

/**
* 连接字符串,AzureBlob控制台-安全性和网络-访问秘钥-连接字符串
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cn.hutool.extra.ssh.Sftp;
import com.aliyun.oss.OSS;
import com.amazonaws.services.s3.AmazonS3;
import com.azure.storage.blob.BlobServiceClient;
import com.baidubce.services.bos.BosClient;
import com.github.sardine.Sardine;
import com.google.cloud.storage.Storage;
Expand All @@ -27,6 +26,7 @@
import org.dromara.x.file.storage.core.exception.FileStorageRuntimeException;
import org.dromara.x.file.storage.core.file.*;
import org.dromara.x.file.storage.core.platform.*;
import org.dromara.x.file.storage.core.platform.AzureBlobStorageFileStorageClientFactory.AzureBlobStorageClient;
import org.dromara.x.file.storage.core.platform.QiniuKodoFileStorageClientFactory.QiniuKodoClient;
import org.dromara.x.file.storage.core.recorder.DefaultFileRecorder;
import org.dromara.x.file.storage.core.recorder.FileRecorder;
Expand Down Expand Up @@ -549,20 +549,20 @@ private Collection<? extends FileStorage> buildFastDfsFileStorage(
}

/**
* 根据配置文件创建 微软 Azure Blob 存储平台
* 根据配置文件创建 Azure Blob Storage 存储平台
*/
public static List<AzureBlobFileStorage> buildAzureBlobFileStorage(
public static List<AzureBlobStorageFileStorage> buildAzureBlobFileStorage(
List<? extends AzureBlobStorageConfig> list, List<List<FileStorageClientFactory<?>>> clientFactoryList) {
if (CollUtil.isEmpty(list)) return Collections.emptyList();
buildFileStorageDetect(list, "microsoft azure blob ", "com.azure.storage.blob.BlobServiceClient");
return list.stream()
.map(config -> {
log.info("加载 microsoft azure blob 存储平台:{}", config.getPlatform());
FileStorageClientFactory<BlobServiceClient> clientFactory = getFactory(
FileStorageClientFactory<AzureBlobStorageClient> clientFactory = getFactory(
config.getPlatform(),
clientFactoryList,
() -> new AzureBlobFileStorageClientFactory(config));
return new AzureBlobFileStorage(config, clientFactory);
() -> new AzureBlobStorageFileStorageClientFactory(config));
return new AzureBlobStorageFileStorage(config, clientFactory);
})
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ interface GoogleCloudStorageACL extends ACL {
String BUCKET_OWNER_FULL_CONTROL = "bucket-owner-full-control";
}

/**
* Azure Blob Storage 的 ACL(已经做了命名规则转换)
* {@link com.azure.storage.file.datalake.models.PathPermissions}
* {@link com.azure.storage.file.datalake.models.PathAccessControlEntry}
* 文档:https://learn.microsoft.com/zh-cn/azure/storage/blobs/data-lake-storage-access-control
*/
interface AzureBlobStorageACL extends ACL {}

/**
* 元数据名称,这里列举的是一些相对通用的名称,但不一定每个存储平台都支持,具体支持情况自行查阅对应存储的相关文档
* <p>阿里云 OSS {@link com.aliyun.oss.model.ObjectMetadata} {@link com.aliyun.oss.internal.OSSHeaders}</p>
Expand All @@ -93,6 +101,7 @@ interface GoogleCloudStorageACL extends ACL {
* <p>又拍云 USS {@link com.upyun.RestManager.PARAMS}</p>
* <p>MinIO {@link io.minio.ObjectWriteArgs}</p>
* <p>GoogleCloud Storage {@link com.google.cloud.storage.BlobInfo} {@link com.google.cloud.storage.Storage.BlobField}</p>
* <p>Azure Blob Storage {@link com.azure.storage.blob.models.BlobHttpHeaders}</p>
*/
interface Metadata {
String CACHE_CONTROL = "Cache-Control";
Expand Down
Loading

0 comments on commit 17e354c

Please sign in to comment.