当前位置: 首页>>代码示例>>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;未经允许,请勿转载。