Bitzsoft.Integrations.CloudDrive.Aliyun 1.0.0-alpha.10

This is a prerelease version of Bitzsoft.Integrations.CloudDrive.Aliyun.
dotnet add package Bitzsoft.Integrations.CloudDrive.Aliyun --version 1.0.0-alpha.10
                    
NuGet\Install-Package Bitzsoft.Integrations.CloudDrive.Aliyun -Version 1.0.0-alpha.10
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitzsoft.Integrations.CloudDrive.Aliyun" Version="1.0.0-alpha.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.CloudDrive.Aliyun" Version="1.0.0-alpha.10" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.CloudDrive.Aliyun" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitzsoft.Integrations.CloudDrive.Aliyun --version 1.0.0-alpha.10
                    
#r "nuget: Bitzsoft.Integrations.CloudDrive.Aliyun, 1.0.0-alpha.10"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitzsoft.Integrations.CloudDrive.Aliyun@1.0.0-alpha.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.CloudDrive.Aliyun&version=1.0.0-alpha.10&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.CloudDrive.Aliyun&version=1.0.0-alpha.10&prerelease
                    
Install as a Cake Tool

Bitzsoft.Integrations.CloudDrive.Aliyun

阿里云网盘与相册服务(PDS)实现,基于 PDS v2 API。

功能特性

  • 基于阿里云网盘与相册服务(PDS)v2 API
  • OAuth 2.0 认证:Bearer Token,支持 RefreshToken 自动刷新(提前 5 分钟刷新,401 自动重试)
  • 文件操作:上传(含秒传)、下载、删除、移动、复制、获取信息
  • 文件夹操作:列表(marker 分页)、创建、删除
  • 文件搜索:支持关键词搜索、类型筛选、扩展名筛选
  • 分享链接:创建分享链接(支持密码和过期时间)、取消分享链接

安装

.NET CLI

dotnet add package Bitzsoft.Integrations.CloudDrive.Aliyun

PackageReference

<PackageReference Include="Bitzsoft.Integrations.CloudDrive.Aliyun" Version="1.0.0" />

配置

appsettings.json

{
  "CloudDrive": {
    "Aliyun": {
      "AccessToken": "初始访问令牌(可选)",
      "RefreshToken": "刷新令牌(必须)",
      "ClientId": "应用 Client ID",
      "ClientSecret": "应用 Client Secret",
      "DomainId": "PDS 实例域名 ID",
      "DriveId": "默认网盘 ID",
      "BaseUrl": "https://{domainId}.api.aliyunpds.com",
      "HttpClientName": "AliyunCloudDrive",
      "LargeFileThreshold": 104857600,
      "ChunkSize": 104857600
    }
  }
}
配置项 必填 默认值 说明
AccessToken -- 初始 OAuth 2.0 访问令牌,未设置时使用 RefreshToken 自动获取
RefreshToken -- OAuth 2.0 刷新令牌
ClientId -- 应用 Client ID
ClientSecret -- 应用 Client Secret
DomainId -- PDS 实例域名 ID,用于拼接 BaseUrl
DriveId -- 默认网盘 ID
BaseUrl 根据 DomainId 自动拼接 API 基地址
HttpClientName AliyunCloudDrive 命名 HttpClient 名称
LargeFileThreshold 104857600(100 MB) 大文件阈值
ChunkSize 104857600(100 MB) 分块上传块大小

注册服务

从 IConfiguration 绑定(推荐)

using Bitzsoft.Integrations.CloudDrive.Aliyun;

builder.Services.AddBitzsoftAliyunCloudDrive(
    builder.Configuration.GetSection("CloudDrive:Aliyun"));

委托配置

builder.Services.AddBitzsoftAliyunCloudDrive(options =>
{
    options.RefreshToken = "your-refresh-token";
    options.ClientId = "your-client-id";
    options.ClientSecret = "your-client-secret";
    options.DomainId = "your-domain-id";
    options.DriveId = "your-drive-id";
});

使用示例

using Bitzsoft.Integrations.CloudDrive.Interfaces;
using Bitzsoft.Integrations.CloudDrive.Models;

public class MyService
{
    private readonly ICloudDriveProvider _drive;

    public MyService(ICloudDriveProvider drive) => _drive = drive;

    public async Task UploadAndListAsync()
    {
        // 上传文件(支持秒传)
        await using var stream = File.OpenRead("report.pdf");
        var upload = await _drive.UploadAsync(new UploadFileRequest
        {
            FolderId = "root",
            FileName = "report.pdf",
            Content = stream,
            ContentType = "application/pdf"
        });

        // 列出文件夹内容(marker 分页)
        var files = await _drive.ListFilesAsync("root");
        foreach (var file in files.Items)
        {
            Console.WriteLine($"{file.Name} ({file.Size} bytes)");
        }

        // 下载文件
        var download = await _drive.DownloadAsync(upload.FileInfo.Id);

        // 搜索文件
        var results = await _drive.SearchAsync(new SearchFilesRequest
        {
            Keyword = "report",
            FileType = DriveFileType.File
        });

        // 创建分享链接(支持密码和过期时间)
        var link = await _drive.CreateShareLinkAsync(new CreateShareLinkRequest
        {
            FileId = upload.FileInfo.Id,
            Password = "1234",
            ExpireTime = DateTime.UtcNow.AddDays(7)
        });
        Console.WriteLine($"分享链接已创建");
    }
}

核心类型一览

类型 说明
AliyunCloudDriveProvider 阿里云 PDS 实现(ProviderName = "Aliyun"
AliyunOptions 配置选项(AccessToken / RefreshToken / ClientId / ClientSecret / DomainId / DriveId 等)
ICloudDriveProvider 企业网盘服务统一抽象接口
UploadFileRequest / UploadFileResult 上传请求与结果(含秒传)
SearchFilesRequest 搜索请求(Keyword / FileType / Extension / 分页)
CreateShareLinkRequest / DriveShareLink 分享链接请求与结果(支持密码、过期时间)

上传流程

  1. POST /v2/file/create -- 创建文件记录,获取预签名上传 URL 和 upload_id
  2. rapid_upload=true,文件已存在(秒传/去重),跳过后续步骤
  3. PUT {upload_url} -- 将文件内容上传到预签名 URL
  4. POST /v2/file/complete -- 完成上传

实现状态

方法 状态 说明
UploadAsync 已实现 创建文件 → 上传预签名 URL → 完成上传;支持秒传
DownloadAsync 已实现 获取预签名下载 URL → GET 下载
DeleteFileAsync 已实现 POST /v2/file/delete
MoveFileAsync 已实现 POST /v2/file/move,支持重命名
CopyFileAsync 已实现 POST /v2/file/copy,支持自动重命名
GetFileInfoAsync 已实现 POST /v2/file/get
ListFilesAsync 已实现 POST /v2/file/list,marker 分页
CreateFolderAsync 已实现 POST /v2/file/create (type=folder)
DeleteFolderAsync 已实现 POST /v2/file/delete(与删除文件共用)
SearchAsync 已实现 POST /v2/file/search,支持类型/扩展名筛选
CreateShareLinkAsync 已实现 POST /v2/share_link/create
DeleteShareLinkAsync 已实现 POST /v2/share_link/cancel
GetPermissionsAsync 不支持 PDS API 不支持独立权限管理
SetPermissionAsync 不支持 PDS API 不支持独立权限管理
DeletePermissionAsync 不支持 PDS API 不支持独立权限管理
ListVersionsAsync 不支持 PDS API 版本管理功能待确认
DownloadVersionAsync 不支持 PDS API 版本管理功能待确认
RestoreVersionAsync 不支持 PDS API 版本管理功能待确认

请求审计

内置 Bitzsoft.Integrations.RequestLogging 出站请求记录管道,默认 NullRequestLogStore 不持久化。

// ① 默认:启用记录管道但不持久化(日志丢弃)
services.AddBitzsoftAliyunCloudDrive(options => { /* ... */ });

// ② 持久化:宿主注册 IRequestLogStore 实现后,所有出站请求自动落库
services.AddRequestLogging<MyRequestLogStore>(opts =>
{
    opts.MaxInMemoryBodyBytes = 64 * 1024; // 仅控制内存/加密临时文件切换,不截断正文
    opts.SensitiveFields.Add("mySecret"); // 额外脱敏字段
});
services.AddBitzsoftAliyunCloudDrive(options => { /* ... */ });

注意事项

  • 阿里云 PDS API 所有文件操作均使用 HTTP POST + JSON body
  • 文件 ID root 表示根目录
  • 令牌过期后自动使用 RefreshToken 刷新,提前 5 分钟刷新避免边界情况
  • 401 响应自动触发令牌刷新并重试请求

依赖

说明
Bitzsoft.Integrations.CloudDrive 企业网盘抽象层
Bitzsoft.Integrations.RequestLogging 出站请求记录管道
Bitzsoft.Integrations.Compatibility 基础工具库
Microsoft.Extensions.Http IHttpClientFactory(连接池)
Microsoft.Extensions.Options.ConfigurationExtensions 配置节点绑定

相关包

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.CloudDrive.Aliyun:

Package Downloads
Bitzsoft.Integrations.CloudDrive.All

企业网盘服务聚合包 — 包含所有供应商实现

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.10 42 7/26/2026
1.0.0-alpha.9 62 7/12/2026
1.0.0-alpha.8 59 7/1/2026
1.0.0-alpha.7 75 6/16/2026
1.0.0-alpha.6 65 6/16/2026
1.0.0-alpha.5 67 6/14/2026
1.0.0-alpha.4 59 7/1/2026
1.0.0-alpha.3 63 6/7/2026