Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Reference

阿里云网盘

阿里云网盘与相册服务(PDS)的 AliyunOptions 配置字段、OAuth 2.0 鉴权、DomainId 拼接与使用示例。

Last updated

包信息

属性值
NuGet 包Bitzsoft.Integrations.CloudDrive.Aliyun
Provider IDaliyun
协议PDS REST API(OAuth 2.0)

配置字段(AliyunOptions)

字段类型必填默认值说明
AccessTokenstring否—OAuth 访问令牌(未设则用 RefreshToken 自动获取)
RefreshTokenstring否—OAuth 刷新令牌
ClientIdstring是—应用 Client ID
ClientSecretstring是—应用 Client Secret
DomainIdstring是—PDS 实例域名 ID
DriveIdstring否—默认网盘 ID
BaseUrlstring否—PDS API 基地址(空则自动拼接 https://{DomainId}.api.aliyunpds.com)
HttpClientNamestring否AliyunCloudDrive命名 HttpClient
LargeFileThresholdlong否100MB大文件分块上传阈值
ChunkSizelong否10MB分块大小
MaxBandwidthBytesPerSecondlong否0上传/下载带宽限流(字节/秒,0 = 不限速,令牌桶算法)
MaxUploadConcurrencyint否3分块上传并发数

配置示例

{
"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。
  • 分块上传默认 10 MB/块,PDS 单分片最大 5 GB。

相关

100%

滚轮或按钮缩放 · 放大后拖动画面 · 双击切换 100% / 200%