當前位置: 首頁>>代碼示例>>C#>>正文


C# Account.CreateClient方法代碼示例

本文整理匯總了C#中Account.CreateClient方法的典型用法代碼示例。如果您正苦於以下問題:C# Account.CreateClient方法的具體用法?C# Account.CreateClient怎麽用?C# Account.CreateClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Account的用法示例。


在下文中一共展示了Account.CreateClient方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Upload

        public async Task<ActionResult> Upload()
        {
            var file = Request.Files[0];

            if (file == null || file.ContentLength < 0) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            if (file.ContentLength > MaxLength) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            if (string.IsNullOrWhiteSpace(file.FileName)) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            var ext = Path.GetExtension(file.FileName);
            if (string.IsNullOrWhiteSpace(ext)) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            ext = ext.Replace(".", "").ToLower();
            if (_permittedExtensions.All(x => x != ext)) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            var data = new byte[file.ContentLength];
            await file.InputStream.ReadAsync(data, 0, file.ContentLength);

            var account = new Account(new Credentials(GlobalSettings.BloqsAccountName, GlobalSettings.BloqsAccessKey), GlobalSettings.BloqsBaseAddress);
            var client = account.CreateClient();
            var container = await client.GetContainerReferenceAsync(LogonUser.Name);
            container.IsPublic = true;
            await container.CreateIfNotExistsAsync();

            var fileInfo = new FileInfo(file.FileName);
            var originalName = fileInfo.Name;
            var extension = fileInfo.Extension;

            var uniquFileName = string.Format("{0}{1}",Guid.NewGuid().ToString("N"), extension);
            var blob = await container.GetBlobReferenceAsync(uniquFileName);

            blob.Properties.CacheControl = "max-age=2592000";
            blob.Properties.ContentDisposition = "inline";
            blob.Properties.ContentType = file.ContentType;

            blob.Metadata["OriginalName"] = originalName;
            blob.Metadata["LogonName"] = LogonUser.LogonName;

            await blob.UploadFromByteArrayAsync(data, 0, data.Length);

            var baseAddress = GlobalSettings.BloqsBaseAddress.EndsWith("/")
                ? GlobalSettings.BloqsBaseAddress
                : GlobalSettings.BloqsBaseAddress + "/";
            var imageUrl = string.Format("{0}{1}/{2}/{3}", baseAddress, GlobalSettings.BloqsAccountName, container.Name, uniquFileName);
            return Json(new { OriginalFileName = originalName, Url = imageUrl });
        }
開發者ID:ksuke,項目名稱:Hinata-on-premise,代碼行數:43,代碼來源:ImageController.cs

示例2: Get

        public async Task<ActionResult> Get(string authorName, string name)
        {
            var account = new Account(new Credentials(GlobalSettings.BloqsAccountName, GlobalSettings.BloqsAccessKey), GlobalSettings.BloqsBaseAddress);
            var client = account.CreateClient();
            var container = await client.GetContainerReferenceAsync(authorName);

            try
            {
                var blob = await container.GetBlobReferenceAsync(name);
                using (var ms = new MemoryStream())
                {
                    await blob.DownloadToStreamAsync(ms);
                    var data = ms.ToArray();
                    return File(data, blob.Properties.ContentType);
                }
            }
            catch
            {
                return HttpNotFound();
            }
        }
開發者ID:ksuke,項目名稱:Hinata-on-premise,代碼行數:21,代碼來源:ImageController.cs


注:本文中的Account.CreateClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。