包信息
| 属性 | 值 |
|---|---|
| NuGet 包 | Bitzsoft.Integrations.CloudDrive.Aliyun |
| Provider ID | aliyun |
| 协议 | PDS REST API(OAuth 2.0) |
配置字段(AliyunOptions)
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
AccessToken | string | 否 | — | OAuth 访问令牌(未设则用 RefreshToken 自动获取) |
RefreshToken | string | 否 | — | OAuth 刷新令牌 |
ClientId | string | 是 | — | 应用 Client ID |
ClientSecret | string | 是 | — | 应用 Client Secret |
DomainId | string | 是 | — | PDS 实例域名 ID |
DriveId | string | 否 | — | 默认网盘 ID |
BaseUrl | string | 否 | — | PDS API 基地址(空则自动拼接 https://{DomainId}.api.aliyunpds.com) |
HttpClientName | string | 否 | AliyunCloudDrive | 命名 HttpClient |
LargeFileThreshold | long | 否 | 100MB | 大文件分块上传阈值 |
ChunkSize | long | 否 | 100MB | 分块大小 |
配置示例
{ "CloudDrive": { "Aliyun": { "ClientId": "your-client-id", "ClientSecret": "your-client-secret", "RefreshToken": "your-refresh-token", "DomainId": "your-domain-id", "DriveId": "your-drive-id" } }}DI 注册
// ① 配置节绑定builder.Services.AddBitzsoftAliyunCloudDrive(builder.Configuration.GetSection("CloudDrive:Aliyun"));
// ② 委托配置builder.Services.AddBitzsoftAliyunCloudDrive(options =>{ options.ClientId = "your-client-id"; options.ClientSecret = "your-client-secret"; options.RefreshToken = "your-refresh-token"; options.DomainId = "your-domain-id";});使用示例
public class DriveService(ICloudDriveProvider drive){ public async Task<UploadFileResult> UploadAsync(string filePath, string folderId) { using var stream = File.OpenRead(filePath); return await drive.UploadAsync(new UploadFileRequest { Stream = stream, FileName = Path.GetFileName(filePath), ParentFolderId = folderId, }); }
public async Task<ListFilesResult> ListAsync(string folderId) { return await drive.ListFilesAsync(folderId); }}已知限制
BaseUrl留空时根据DomainId自动拼接为https://{DomainId}.api.aliyunpds.com。- 分块上传默认 100 MB/块,PDS 单分片最大 5 GB。