Example #1
0
        /// <summary>
        /// 获取bucket下的文件列表
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="markerIn"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <string> > ListAsync(string prefix = "", string markerIn = "", int limit = 0)
        {
            RSFClient client  = new RSFClient(_bucket);
            DumpRet   dumpRet = await client.ListPrefixAsync(_bucket, prefix, markerIn, limit);

            return(dumpRet.Items.Select(i => i.Key));
        }
Example #2
0
        public async Task ListPrefixTest()
#endif
        {
            RSFClient target = new RSFClient(Bucket);  // TODO: 初始化为适当的值

            target.Marker = string.Empty;
            target.Prefix = "csharp";
            target.Limit  = 3;
            DumpRet actual;

#if NET20 || NET40
            actual = target.ListPrefix(Bucket);
            foreach (DumpItem item in actual.Items)
            {
                Console.WriteLine("Key:{0},Hash:{1},Mime:{2},PutTime:{3},EndUser:{4}", item.Key, item.Hash, item.Mime, item.PutTime, item.EndUser);
            }

            //error params
            Assert.IsTrue(actual.Items.Count >= 3, "ListPrefixTest Failure");
#else
            actual = await target.ListPrefixAsync(Bucket);

            foreach (DumpItem item in actual.Items)
            {
                Console.WriteLine("Key:{0},Hash:{1},Mime:{2},PutTime:{3},EndUser:{4}", item.Key, item.Hash, item.Mime, item.PutTime, item.EndUser);
            }

            //error params
            Assert.True(actual.Items.Count >= 3, "ListPrefixTest Failure");
#endif
        }
Example #3
0
        public static DumpRet GetUEditorFileUploadToday()
        {
            var       policy = new PutPolicy(bucket, 3600);
            RSFClient client = new RSFClient(bucket);

            var picColl = client.ListPrefix(bucket, "", "");

            return(picColl);
        }
Example #4
0
        public IEnumerable <string> GetFiles(string path, string filter)
        {
            List <string> list = new List <string>();

            RSFClient rsf = new RSFClient(bucket);

            rsf.Prefix = "";
            rsf.Limit  = 100;
            List <DumpItem> items;

            items = rsf.Next();
            return(items.Where(z => true).Select(z => z.Key));
        }
Example #5
0
        private async Task <object> ListFile(string prefix = "image")
        {
            var start = int.Parse(Request.Query["start"].ToString());
            var size  = int.Parse(Request.Query["size"].ToString());

            var rsf   = new RSFClient(Config.Bucket);
            var files = await rsf.ListPrefixAsync(Config.Bucket, prefix);

            var list = files.Items.Select(p => string.Format("{0}/{1}{2}", Config.Domain, p.Key, prefix == "image" ? Config.Suffix : "")).OrderByDescending(p => p).Skip(start).Take(size).ToList();

            return(new
            {
                state = "SUCCESS",
                list = list == null ? null : list.Select(x => new { url = x }),
                start = start,
                size = size,
                total = files.Items.Count
            });
        }
Example #6
0
        public void DeleteDirectory(string path, bool recursive)
        {
            path = this.FixPath(path);

            if (!this.DirectoryExists(path))
            {
                return;
            }

            //处理path中反斜杠
            path = EnsureUrlSeparatorChar(path);
            path = path.TrimStart('/');
            var _prefix = path;//处理path 得到前缀

            RSFClient rsf = new RSFClient(bucket);

            rsf.Prefix = _prefix;
            rsf.Limit  = 100;
            List <DumpItem> items;

            items = rsf.Next();

            if (items != null)
            {
                foreach (var item in items)
                {
                    //实例化一个RSClient对象,用于操作BucketManager里面的方法
                    RSClient client = new RSClient();
                    CallRet  ret    = client.Delete(new EntryPath(bucket, item.Key));

                    if (ret.OK)
                    {
                        LogHelper.Info <PutRet>("七牛删除 成功");
                    }
                    else
                    {
                        LogHelper.Info <PutRet>("七牛删除 失败");
                    }
                }
            }
        }
Example #7
0
        //TODO:未完成
        public bool DirectoryExists(string path)
        {
            //处理path中反斜杠
            path = EnsureUrlSeparatorChar(path);
            path = path.TrimStart('/');

            //判断这个前缀在七牛云中能否找到对应文件
            RSFClient rsf = new RSFClient(bucket);

            rsf.Prefix = path;
            rsf.Limit  = 100;
            List <DumpItem> items;

            items = rsf.Next();
            if (items == null)
            {
                return(false);
            }

            return(items.Count > 0);
        }
Example #8
0
        public IEnumerable <string> GetDirectories(string path)
        {
            List <string> list = new List <string>();

            RSFClient rsf = new RSFClient(bucket);

            rsf.Prefix = "";
            rsf.Limit  = 100;
            List <DumpItem> items;

            items = rsf.Next();
            if (items != null)
            {
                foreach (var item in items)
                {
                    var preifx = item.Key.Split('/')[0];
                    list.Add(preifx);
                }
            }

            return(list.Where(z => true));
        }