1.打开百度智能云 https://console.bce.baidu.com/ 注册登录
2.鼠标右上角头像图标弹出选择 “安全认证”获取 访问密钥IDAccess Key Id, 后文简称AK)和秘密访问密钥Secret Access Key, 后文简称SK)
3.打开BOS服务,开通服务,进入到创建Buckets界面,发现要收费,没有继续了。代码只有一部分可以运行,仅供参考
4.打开VS,新建项目, Nuget搜索BceSdkDotNet,应用到项目,代码如下
class Program { public static void FileDownLoad) { var client = GenerateBosClient); var bucketName = "/Program"; //指定Bucket名称文件夹名称) var objectKey = "分布式数据库结构图.fw.png"; //指定object名称(文件名字)// 获取Object var bosObject = client.GetObjectbucketName, objectKey); var meta = bosObject.ObjectMetadata; var objectContent = bosObject.ObjectContent; var fileStream = new FileInfoobjectKey).OpenWrite); //指定下载文件的目录/文件名 var buffer = new byte[2048]; int count = 0; while count = objectContent.Readbuffer, 0, buffer.Length)) > 0) { fileStream.Writebuffer, 0, count); } // 关闭流 objectContent.Close); fileStream.Close); } private static BosClient GenerateBosClient) { const string accessKeyId = ""; // 您的Access Key ID const string secretAccessKey = ""; // 您的Secret Access Key const string endpoint = "http://bj.bcebos.com"; //指定Bucket所在区域域名 // 初始化一个BosClient BceClientConfiguration config = new BceClientConfiguration); config.Credentials = new DefaultBceCredentialsaccessKeyId, secretAccessKey); config.Endpoint = endpoint; return new BosClientconfig); } public static void GetBuckets) { BosClient client = GenerateBosClient); List<BucketSummary> buckets = client.ListBuckets).Buckets; foreach BucketSummary bucket in buckets) { Console.WriteLinebucket.Name); } } static void Mainstring[] args) { GetBuckets); FileDownLoad); } }