Bitzsoft.Integrations.CloudDrive.Baidu
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Bitzsoft.Integrations.CloudDrive.Baidu --version 1.0.0
NuGet\Install-Package Bitzsoft.Integrations.CloudDrive.Baidu -Version 1.0.0
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.Baidu" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.CloudDrive.Baidu" Version="1.0.0" />
<PackageReference Include="Bitzsoft.Integrations.CloudDrive.Baidu" />
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.Baidu --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.CloudDrive.Baidu, 1.0.0"
#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.Baidu@1.0.0
#: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.Baidu&version=1.0.0
#tool nuget:?package=Bitzsoft.Integrations.CloudDrive.Baidu&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.CloudDrive.Baidu
百度网盘服务实现,基于百度网盘开放平台 API。
功能特性
- 基于百度网盘开放平台 API,支持文件上传、下载、列表查询和文件夹管理
- OAuth 2.0 认证:访问令牌由外部授权码流获取,配置 RefreshToken 后支持自动刷新
- 大文件分块上传:precreate / chunks / create 三步流程
- 文件管理:复制、移动、删除
- 文件搜索:递归搜索
安装
.NET CLI
dotnet add package Bitzsoft.Integrations.CloudDrive.Baidu
PackageReference
<PackageReference Include="Bitzsoft.Integrations.CloudDrive.Baidu" Version="1.0.0" />
配置
appsettings.json
{
"CloudDrive": {
"Baidu": {
"AccessToken": "通过 OAuth 授权码流获取的访问令牌",
"RefreshToken": "刷新令牌(可选,用于自动刷新)",
"AppKey": "应用 App Key(刷新令牌时需要)",
"SecretKey": "应用 Secret Key(刷新令牌时需要)",
"AppName": "百度网盘应用名称",
"BaseUrl": "https://pan.baidu.com/rest/2.0/",
"UploadBaseUrl": "https://d.pcs.baidu.com/rest/2.0/pcs/superfile2",
"TokenEndpoint": "https://openapi.baidu.com/oauth/2.0/token",
"LargeFileThreshold": 4194304,
"ChunkSize": 4194304,
"HttpClientName": "BaiduCloudDrive"
}
}
}
| 配置项 | 必填 | 默认值 | 说明 |
|---|---|---|---|
AccessToken |
是 | -- | OAuth 2.0 访问令牌 |
RefreshToken |
否 | -- | 刷新令牌,配置后支持自动刷新 |
AppKey |
否 | -- | 应用 App Key,刷新令牌时需要 |
SecretKey |
否 | -- | 应用 Secret Key,刷新令牌时需要 |
AppName |
是 | -- | 百度网盘应用名称,用于拼接文件路径前缀 |
BaseUrl |
否 | https://pan.baidu.com/rest/2.0/ |
API 基地址 |
UploadBaseUrl |
否 | https://d.pcs.baidu.com/rest/2.0/pcs/superfile2 |
分块上传基地址 |
TokenEndpoint |
否 | https://openapi.baidu.com/oauth/2.0/token |
OAuth 令牌端点 |
LargeFileThreshold |
否 | 4194304(4 MB) |
大文件分块上传阈值 |
ChunkSize |
否 | 4194304(4 MB) |
分块上传每块大小 |
HttpClientName |
否 | BaiduCloudDrive |
命名 HttpClient 名称 |
注册服务
从 IConfiguration 绑定(推荐)
using Bitzsoft.Integrations.CloudDrive.Baidu;
builder.Services.AddBitzsoftBaiduCloudDrive(
builder.Configuration.GetSection("CloudDrive:Baidu"));
委托配置
builder.Services.AddBitzsoftBaiduCloudDrive(options =>
{
options.AccessToken = "你的访问令牌";
options.RefreshToken = "你的刷新令牌";
options.AppKey = "你的应用 Key";
options.SecretKey = "你的应用密钥";
options.AppName = "你的应用名称";
});
使用示例
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("video.mp4");
var upload = await _drive.UploadAsync(new UploadFileRequest
{
FolderId = "/",
FileName = "video.mp4",
Content = stream,
ContentLength = stream.Length,
ContentType = "video/mp4"
});
// 列出文件夹内容
var files = await _drive.ListFilesAsync("/");
foreach (var file in files.Items)
{
Console.WriteLine($"{file.Name} ({file.Size} bytes)");
}
// 下载文件(两步:获取 dlink + 下载内容)
var download = await _drive.DownloadAsync(upload.FileInfo.Id);
// 搜索文件(递归)
var results = await _drive.SearchAsync(new SearchFilesRequest
{
Keyword = "video"
});
}
}
核心类型一览
| 类型 | 说明 |
|---|---|
BaiduCloudDriveProvider |
百度网盘实现(ProviderName = "Baidu") |
BaiduOptions |
配置选项(AccessToken / RefreshToken / AppKey / SecretKey / AppName 等) |
ICloudDriveProvider |
企业网盘服务统一抽象接口 |
UploadFileRequest / UploadFileResult |
上传请求与结果 |
SearchFilesRequest |
搜索请求(递归搜索) |
实现状态
| 方法 | 状态 | 说明 |
|---|---|---|
UploadAsync |
已实现 | 三步分块上传:precreate + chunks + create |
DownloadAsync |
已实现 | 两步下载:获取 dlink + 下载内容 |
DeleteFileAsync |
已实现 | filemanager?opera=delete |
MoveFileAsync |
已实现 | filemanager?opera=move |
CopyFileAsync |
已实现 | filemanager?opera=copy |
GetFileInfoAsync |
已实现 | multimedia?method=filemetas |
ListFilesAsync |
已实现 | /xpan/file?method=list,支持分页 |
CreateFolderAsync |
已实现 | /xpan/file?method=create&isdir=1 |
DeleteFolderAsync |
已实现 | filemanager?opera=delete |
SearchAsync |
已实现 | /xpan/file?method=search |
CreateShareLinkAsync |
不支持 | 需企业级开发者审批 |
DeleteShareLinkAsync |
不支持 | 需企业级开发者审批 |
GetPermissionsAsync |
不支持 | API 不支持独立权限管理 |
SetPermissionAsync |
不支持 | API 不支持独立权限管理 |
DeletePermissionAsync |
不支持 | API 不支持独立权限管理 |
ListVersionsAsync |
不支持 | API 不支持版本管理 |
DownloadVersionAsync |
不支持 | API 不支持版本管理 |
RestoreVersionAsync |
不支持 | API 不支持版本管理 |
请求审计
内置 Bitzsoft.Integrations.RequestLogging 出站请求记录管道,默认 NullRequestLogStore 不持久化。
// ① 默认:启用记录管道但不持久化(日志丢弃)
services.AddBitzsoftBaiduCloudDrive(options => { /* ... */ });
// ② 持久化:宿主注册 IRequestLogStore 实现后,所有出站请求自动落库
services.AddRequestLogging<MyRequestLogStore>(opts =>
{
opts.MaxInMemoryBodyBytes = 64 * 1024; // 仅控制内存/加密临时文件切换,不截断正文
opts.SensitiveFields.Add("mySecret"); // 额外脱敏字段
});
services.AddBitzsoftBaiduCloudDrive(options => { /* ... */ });
注意事项
- 百度网盘要求文件路径必须以
/apps/{appName}/为前缀,AppName配置项用于指定应用名称 - 文件 ID 使用
fs_id(文件系统 ID)的字符串表示 - 访问令牌通过外部 OAuth 授权码流程获取,可配置 RefreshToken 实现自动刷新
- 大文件(超过 4 MB 默认阈值)自动使用三步分块上传流程
- 下载文件需要两步操作:先获取下载链接(dlink),再通过 dlink 下载内容
依赖
| 包 | 说明 |
|---|---|
Bitzsoft.Integrations.CloudDrive |
企业网盘抽象层 |
Bitzsoft.Integrations.RequestLogging |
出站请求记录管道 |
Bitzsoft.Integrations.Compatibility |
基础工具库 |
Microsoft.Extensions.Http |
IHttpClientFactory(连接池) |
Microsoft.Extensions.Options.ConfigurationExtensions |
配置节点绑定 |
相关包
- Bitzsoft.Integrations.CloudDrive -- 抽象层
- Bitzsoft.Integrations.CloudDrive.All -- 聚合包(一键注册全部供应商)
- Bitzsoft.Integrations.CloudDrive.Nutstore -- 坚果云
- Bitzsoft.Integrations.CloudDrive.Microsoft365 -- Microsoft 365 / OneDrive
- Bitzsoft.Integrations.CloudDrive.Gokuai -- 够快云库
- Bitzsoft.Integrations.CloudDrive.AnyShare -- 爱数 AnyShare
- Bitzsoft.Integrations.CloudDrive.Aliyun -- 阿里云网盘 PDS
- Bitzsoft.Integrations.Compatibility -- 基础工具库
| Product | Versions 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.
-
net10.0
- Bitzsoft.Integrations.CloudDrive (>= 1.0.0)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
-
net5.0
- Bitzsoft.Integrations.CloudDrive (>= 1.0.0)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Http (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
-
net8.0
- Bitzsoft.Integrations.CloudDrive (>= 1.0.0)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.CloudDrive.Baidu:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.CloudDrive.All
企业网盘服务聚合包 — 包含所有供应商实现 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 135 | 8/3/2026 |
| 1.0.0 | 131 | 8/2/2026 |
| 1.0.0-alpha.10 | 51 | 7/26/2026 |
| 1.0.0-alpha.9 | 68 | 7/12/2026 |
| 1.0.0-alpha.8 | 71 | 7/1/2026 |
| 1.0.0-alpha.7 | 78 | 6/16/2026 |
| 1.0.0-alpha.6 | 75 | 6/16/2026 |
| 1.0.0-alpha.5 | 68 | 6/14/2026 |
| 1.0.0-alpha.4 | 72 | 7/1/2026 |
| 1.0.0-alpha.3 | 70 | 6/7/2026 |