示例#1
0
 /// <summary>
 /// 阿里云文件夹
 /// </summary>
 /// <returns></returns>
 public static string SetPath()
 {
     var Path = DateTime.Now.ToString("yyyyMM/");
     var listObjectsRequest = new ListObjectsRequest(bucketName);
     listObjectsRequest.Prefix = Path;
     var result = client.ListObjects(listObjectsRequest);
     if (result.CommonPrefixes.Count() != 0)
     {
         using (var stream = new MemoryStream())
         {
             client.PutObject(bucketName, Path, stream);
         }
     }
     return Path;
 }
示例#2
0
 /// <summary>
 /// 列出存储空间内的所有文件
 /// </summary>
 private static void ListObjects()
 {
     try
     {
         var keys = new List<string>();
         ObjectListing result = null;
         string nextMarker = string.Empty;
         /// 由于ListObjects每次最多返回100个结果,所以,这里需要循环去获取,直到返回结果中IsTruncated为false
         do
         {
             var listObjectsRequest = new ListObjectsRequest(_bucketName)
             {
                 Marker = nextMarker,
                 MaxKeys = 100
             };
             result = _client.ListObjects(listObjectsRequest);
             foreach (var summary in result.ObjectSummaries)
             {
                 keys.Add(summary.Key);
             }
             nextMarker = result.NextMarker;
         } while (result.IsTruncated);
         Console.WriteLine("列出存储空间中的文件");
         foreach (var key in keys)
         {
             Console.WriteLine("文件名称:{0}", key);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("列出存储空间中的文件失败.原因: {0}", ex.Message);
     }
 }
示例#3
0
文件: OssFile.cs 项目: NoCat/mp
 public static ObjectListing ListObjects(string maker)
 {
     ListObjectsRequest request = new ListObjectsRequest(_bucketName);
     request.Marker = maker;
     return _client.ListObjects(request);
 }
        public void ListAllObjectsTest()
        {
            //test folder structure
            var folderName = OssTestUtils.GetObjectKey(_className);
            var key = folderName + "/" + OssTestUtils.GetObjectKey(_className);

            try
            {
                //upload the object
                OssTestUtils.UploadObject(_ossClient, _bucketName, key,
                    Config.UploadSampleFile, new ObjectMetadata());

                //list objects by specifying bucket name
                var allObjects = _ossClient.ListObjects(_bucketName);
                //default value is 100
                Assert.AreEqual(100, allObjects.MaxKeys);
                var allObjectsSumm = allObjects.ObjectSummaries.ToList();
                //there is already one sample object
                Assert.AreEqual(2, allObjectsSumm.Count);

                //list objects by specifying folder as prefix
                allObjects = _ossClient.ListObjects(_bucketName, folderName);
                Assert.AreEqual(folderName, allObjects.Prefix);
                allObjectsSumm = allObjects.ObjectSummaries.ToList();
                Assert.AreEqual(1, allObjectsSumm.Count);

                var loRequest = new ListObjectsRequest(_bucketName);
                loRequest.Prefix = folderName;
                loRequest.MaxKeys = 10;
                loRequest.Delimiter = "/";
                allObjects = _ossClient.ListObjects(loRequest);
                Assert.AreEqual(folderName, allObjects.Prefix);
                Assert.AreEqual("/", allObjects.Delimiter);
                //Assert.Fail("List objects using full conditions");
            }
            finally
            {
                _ossClient.DeleteObject(_bucketName, key);
            }
        }