/// <summary>
        /// 增加文件管理
        /// </summary>
        /// <param name="connectionString">Blob的连接字符串</param>
        /// <param name="containerString">默认容器名称</param>
        /// <param name="rootDirectory">根文件夹路径</param>
        public static IServiceCollection AddFileManager(this IServiceCollection services, string connectionString, string containerString, string rootDirectory = "upload")
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }
            if (string.IsNullOrEmpty(containerString))
            {
                throw new ArgumentNullException(nameof(containerString));
            }

            var storage = new OssFileStorage(connectionString);

            storage.DefaultBucket = containerString;
            storage.RootDirectory = rootDirectory;

            var parser = new OssFilenameParser();

            services.AddSingleton <IFileManager>(new FileManager(storage, parser));

            return(services);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var storage = new OssFileStorage("");

            storage.DefaultBucket = "";
            storage.RootDirectory = "";

            var parser = new OssFilenameParser();

            var fm = new FileManager(storage, parser);

            using (MemoryStream ms = new MemoryStream())
            {
                var txt = Encoding.UTF8.GetBytes("测试数据");
                ms.Write(txt, 0, txt.Length);

                var filename = fm.SaveAsync(ms, "test.txt").Result;
                var isexists = fm.ExistsAsync(filename).Result;
                var obj      = fm.GetAsync(filename).Result;
            }
            Console.WriteLine("Hello World!");
        }