private void comboBox_Domain_Click(object sender, EventArgs e) { if (textBox_AK.Text != "" && textBox_SK.Text != "" && textBox_bucket_name.Text != "") { comboBox_Domain.Items.Clear(); comboBox_Domain.Items.Add("Loading..."); Mac mac = new Mac(textBox_AK.Text, textBox_SK.Text); Config config = new Config { // 设置上传区域 //Zone = Zone.ZONE_CN_East, // 设置 http 或者 https 上传 UseHttps = true, UseCdnDomains = true, ChunkSize = ChunkUnit.U512K }; BucketManager bm = new BucketManager(mac, config); DomainsResult DomainRet = bm.Domains(textBox_bucket_name.Text); comboBox_Domain.Items.Clear(); if (DomainRet.Result != null) { for (int i = 0; i < DomainRet.Result.Count; i++) { comboBox_Domain.Items.Add(DomainRet.Result[i]); } } } }
public void DomainsTest() { Mac mac = new Mac(AccessKey, SecretKey); BucketManager target = new BucketManager(mac); DomainsResult result = target.Domains(Bucket1); Assert.AreEqual((int)HttpCode.OK, result.Code); }
/// <summary> /// 获取指定bucket对应的域名(可能不止一个),类似于abcxx.bkt.clouddn.com这样 /// </summary> public static void domains() { Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey); string bucket = "BUCKET"; BucketManager bm = new BucketManager(mac); DomainsResult result = bm.domains(bucket); foreach (string domain in result.Domains) { System.Console.WriteLine(domain); } }
public void DomainsTest() { Config config = new Config(); config.Zone = Zone.ZONE_CN_East; Mac mac = new Mac(AccessKey, SecretKey); BucketManager bucketManager = new BucketManager(mac, config); DomainsResult ret = bucketManager.Domains(Bucket); if (ret.Code != (int)HttpCode.OK) { Assert.Fail("domains error: " + ret.ToString()); } Console.WriteLine(ret.ToString()); }
private void button2_Click(object sender, EventArgs e) { string localFile = textBox1.Text.Trim(); FileInfo fi = new FileInfo(localFile); string saveKey = fi.Name; string bucket = comboBox1.Text; // 生成上传凭证 Mac mac = this.GetMac(); BucketManager bm = new BucketManager(mac); //BucketsResult rs = bm.buckets(); DomainsResult dr = bm.domains(bucket); this.BucDomain = dr.Domains[0]; //this.BucDomain // 上传策略 PutPolicy putPolicy = new PutPolicy(); // 设置要上传的目标空间 putPolicy.Scope = bucket; // 上传策略的过期时间(单位:秒) putPolicy.SetExpires(3600); // 文件上传完毕后,在多少天后自动被删除 putPolicy.DeleteAfterDays = 0; // 请注意这里的Zone设置(如果不设置,就默认为华东机房) // var zoneId = Qiniu.Common.AutoZone.Query(AK,BUCKET); // Qiniu.Common.Config.ConfigZone(zoneId); string uploadToken = Auth.createUploadToken(putPolicy, mac); UploadOptions uploadOptions = null; // 上传完毕事件处理 UpCompletionHandler uploadCompleted = new UpCompletionHandler(OnUploadCompleted); // 方式1:使用UploadManager //默认设置 Qiniu.Common.Config.PUT_THRESHOLD = 512*1024; //可以适当修改,UploadManager会根据这个阈值自动选择是否使用分片(Resumable)上传 UploadManager um = new UploadManager(); um.uploadFile(localFile, saveKey, uploadToken, uploadOptions, uploadCompleted); // 方式2:使用FormManager //FormUploader fm = new FormUploader(); //fm.uploadFile(localFile, saveKey, token, uploadOptions, uploadCompleted); //Console.ReadKey(); }
private void SyncTargetBucketsComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { num = 1; marker = ""; btnSearch.Content = "查询"; btnSearch.IsEnabled = true; btnUpload.IsEnabled = true; btnBatchDel.IsEnabled = true; btnBatchDownload.IsEnabled = true; if (SyncTargetBucketsComboBox.SelectedValue != null) { bucket = SyncTargetBucketsComboBox.SelectedValue.ToString(); DomainsComboBox.Items.Clear(); //多线程处理 ThreadPool.QueueUserWorkItem((state) => { domainsResult = bucketManager.Domains(bucket); Dispatcher.Invoke(new Action(() => { if (domainsResult.Result.Count > 0) { foreach (string domain in domainsResult.Result) { DomainsComboBox.Items.Add(domain); } DomainsComboBox.SelectedValue = DomainsComboBox.Items[0]; } })); }); //domainsResult = bucketManager.Domains(bucket); //if (domainsResult.Result.Count > 0) //{ // foreach (string domain in domainsResult.Result) // { // DomainsComboBox.Items.Add(domain); // } // DomainsComboBox.SelectedValue = DomainsComboBox.Items[0]; //} } qiNiuFileInfoList = new List <QiNiuFileInfo>(); }
public void bktMgrTest() { //Settings.load(); Settings.LoadFromFile(); string testResUrl = "http://test.fengyh.cn/qiniu/files/hello.txt"; Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey); BucketManager target = new BucketManager(mac); target.fetch(testResUrl, Settings.Bucket, "test_BucketManager.txt"); target.stat(Settings.Bucket, "test_BucketManager.txt"); target.copy(Settings.Bucket, "test_BucketManager.txt", Settings.Bucket, "copy_BucketManager.txt", true); target.move(Settings.Bucket, "copy_BucketManager.txt", Settings.Bucket, "move_BucketManager.txt", true); target.delete(Settings.Bucket, "test_BucketManager.txt"); DomainsResult domainsResult = target.domains(Settings.Bucket); BucketsResult bucketsResult = target.buckets(); }
/// <summary> /// 查询 /// </summary> private void Search() { if (string.IsNullOrWhiteSpace(marker)) { num = 1; btnSearch.Content = "查询"; } else { btnSearch.Content = "加载更多"; } bucket = SyncTargetBucketsComboBox.Text; ListResult listResult = bucketManager.ListFiles(bucket, txtStartWith.Text, marker, 1000, ""); // DomainsResult domainsResult = bucketManager.Domains(SyncTargetBucketsComboBox.Text); domainsResult = bucketManager.Domains(bucket); if (listResult.Result.Items.Count >= 1000) { btnSearch.Content = "加载更多"; } else { num = 1; marker = ""; btnSearch.Content = "查询"; } if (qiNiuFileInfoList == null || num == 1) { qiNiuFileInfoList = new List <QiNiuFileInfo>(); } foreach (ListItem item in listResult.Result.Items) { // item.EndUser QiNiuFileInfo f = new QiNiuFileInfo { Num = num, FileName = item.Key, FileType = item.MimeType, StorageType = QiNiuHelper.GetStorageType(item.FileType), FileSize = QiNiuHelper.GetFileSize(item.Fsize), EndUser = item.EndUser, CreateDate = QiNiuHelper.GetDataTime(item.PutTime) }; qiNiuFileInfoList.Add(f); num++; } marker = listResult.Result.Marker; if (qiNiuFileInfoList.Count > 0) { dgResult.ItemsSource = !string.IsNullOrWhiteSpace(txtEndWith.Text) ? qiNiuFileInfoList.Where(f => f.FileName.EndsWith(txtEndWith.Text.Trim())) : qiNiuFileInfoList; } else { dgResult.ItemsSource = new List <QiNiuFileInfo>(); } }