/// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="fileName"></param>
        private static bool BlobUpload(string fileName)
        {
            try
            {
                Console.WriteLine("开始上传文件");
                UBA.Common.LogHelperNet.Info("开始上传文件", null);
                var start = DateTime.Now;
                BlobStorageManager blob = new BlobStorageManager("StorageConnectionString");
                var inputContainer = System.Configuration.ConfigurationManager.AppSettings["ContainerName"];
                //删除容器
                blob.DeleteContainer("ubadata");
                UBA.Common.LogHelperNet.Info("开始创建容器", null);
                blob.CreateContainer(inputContainer);
                UBA.Common.LogHelperNet.Info("创建容器成功", null);
                var blobName = Path.GetFileNameWithoutExtension(fileName) + ".txt";

                Task.WaitAll(blob.UploadFromFile(fileName, inputContainer, blobName));

                UBA.Common.LogHelperNet.Info("上传成功--耗时:" + DateTime.Now.Subtract(start).TotalMilliseconds, null);
                Console.WriteLine("上传成功");
                Console.WriteLine(DateTime.Now.Subtract(start).TotalMilliseconds);
                return true;
            }
            catch (Exception ex)
            {
                UBA.Common.LogHelperNet.Error("上传文件失败", ex);
                return false;
            }
        }
Exemple #2
0
 private static void BlobUpload(string fileName)
 {
     var start = DateTime.Now;
     BlobStorageManager blob = new BlobStorageManager("StorageConnectionString");
     var inputContainer = System.Configuration.ConfigurationManager.AppSettings["ContainerName"];
     blob.CreateContainer(inputContainer);
     var blobName = Path.GetFileNameWithoutExtension(fileName) + ".txt";
     Task.WaitAll(blob.UploadFromFile(fileName, inputContainer, blobName));
     Console.WriteLine(DateTime.Now.Subtract(start).TotalMilliseconds);
 }
Exemple #3
0
        private static bool PutBlockToBlob(string fileName)
        {
            try
            {
                Console.WriteLine("开始上传文件");
                var start = DateTime.Now;
                BlobStorageManager blob = new BlobStorageManager("StorageConnectionString");
                var inputContainer = System.Configuration.ConfigurationManager.AppSettings["ContainerName"];
                UBA.Common.LogHelperNet.Info("开始创建容器", null);
                blob.CreateContainer(inputContainer);
                UBA.Common.LogHelperNet.Info("创建容器成功", null);
                var blobName = Path.GetFileNameWithoutExtension(fileName) + ".txt";

                using (FileStream fs = new FileStream(fileName, FileMode.Open))
                {
                    byte[] bytes = new byte[1024 * 1024 * 3];
                    int k = 0;
                    int id = 0;
                    List<string> blobIds = new List<string>();
                    while ((k = fs.Read(bytes, 0, bytes.Length)) > 0)
                    {
                        id++;
                        blob.PutBlock(inputContainer, blobName, id, blobIds, bytes);
                    }
                    blob.PutBlockList(inputContainer, blobName, blobIds);

                }
                UBA.Common.LogHelperNet.Info("上传成功--耗时:" + DateTime.Now.Subtract(start).TotalMilliseconds, null);
                Console.WriteLine("上传成功");
                Console.WriteLine(DateTime.Now.Subtract(start).TotalMilliseconds);
                return true;
            }
            catch (Exception ex)
            {
                UBA.Common.LogHelperNet.Error("上传文件失败", ex);
                return false;
            }
        }