当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlockBlob.UploadFromStreamAsync方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlockBlob.UploadFromStreamAsync方法的具体用法?C# CloudBlockBlob.UploadFromStreamAsync怎么用?C# CloudBlockBlob.UploadFromStreamAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob的用法示例。


在下文中一共展示了CloudBlockBlob.UploadFromStreamAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadBlockBlobAsync

 public async virtual void UploadBlockBlobAsync(CloudBlockBlob blockBlob, Stream streamToUpload, AccessCondition accessCondition = null)
 {
     await blockBlob.UploadFromStreamAsync(streamToUpload, accessCondition, null, null);
 }
开发者ID:jjschlesinger,项目名称:DefiantCode.Components,代码行数:4,代码来源:CloudBlobManager.cs

示例2: Upload

        public async Task Upload(Stream blob, string containerName, string path)
        {
            CloudBlobContainer container = _blobClient.GetContainerReference(containerName);

            container.CreateIfNotExists();
            container.SetPermissions(new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            _blockBlob = container.GetBlockBlobReference(path);

            using (var fileStream = blob)
            {
                await _blockBlob.UploadFromStreamAsync(fileStream);
            }
        }
开发者ID:Lejdholt,项目名称:Muztache,代码行数:17,代码来源:BlobService.cs

示例3: TestBlobSASAsync

        /// <summary>
        /// Tests a blob SAS to determine which operations it allows.
        /// </summary>
        /// <param name="sasUri">A string containing a URI with a SAS appended.</param>
        /// <param name="blobContent">A string content content to write to the blob.</param>
        /// <returns>A Task object.</returns>
        private static async Task TestBlobSASAsync(string sasUri, string blobContent)
        {
            // Try performing blob operations using the SAS provided.

            // Return a reference to the blob using the SAS URI.
            CloudBlockBlob blob = new CloudBlockBlob(new Uri(sasUri));

            // Create operation: Upload a blob with the specified name to the container.
            // If the blob does not exist, it will be created. If it does exist, it will be overwritten.
            try
            {
                MemoryStream msWrite = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
                msWrite.Position = 0;
                using (msWrite)
                {
                    await blob.UploadFromStreamAsync(msWrite);
                }

                Console.WriteLine("Create operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Create operation failed for SAS {0}", sasUri);
                    Console.WriteLine("Additional error information: " + e.Message);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    throw;
                }
            }

            // Write operation: Add metadata to the blob
            try
            {
                await blob.FetchAttributesAsync();
                string rnd = new Random().Next().ToString();
                string metadataName = "name";
                string metadataValue = "value";
                blob.Metadata.Add(metadataName, metadataValue);
                await blob.SetMetadataAsync();

                Console.WriteLine("Write operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Write operation failed for SAS {0}", sasUri);
                    Console.WriteLine("Additional error information: " + e.Message);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    throw;
                }
            }

            // Read operation: Read the contents of the blob.
            try
            {
                MemoryStream msRead = new MemoryStream();
                using (msRead)
                {
                    await blob.DownloadToStreamAsync(msRead);
                    msRead.Position = 0;
                    using (StreamReader reader = new StreamReader(msRead, true))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                        }
                    }

                    Console.WriteLine();
                }

                Console.WriteLine("Read operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Read operation failed for SAS {0}", sasUri);
//.........这里部分代码省略.........
开发者ID:tamram,项目名称:storage-blob-dotnet-getting-started,代码行数:101,代码来源:Advanced.cs

示例4: UploadPhoto

        /// <summary>
        /// Uploads the photo.
        /// </summary>
        /// <param name="stream">The memory stream.</param>
        /// <param name="localPath">The local path.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="categoryId">The id of the assocaited category.</param>
        /// <returns>The uploaded photo.</returns>
        public async Task<Photo> UploadPhoto(Stream stream, string localPath, string caption, string categoryId)
        {
            try
            {
                var sasContracts = await GetSasUrls();

                // Upload photos into azure
                foreach (var sasContract in sasContracts)
                {
                    var blob =
                        new CloudBlockBlob(
                            new Uri($"{sasContract.FullBlobUri}{sasContract.SasToken}"));

                    var sideLength = sasContract.SasPhotoType.ToSideLength();

                    var resizedStream = await BitmapTools.Resize(
                        stream.AsRandomAccessStream(), sideLength,
                        sideLength);

                    await blob.UploadFromStreamAsync(resizedStream);
                }

                var photoContract = new PhotoContract
                {
                    CategoryId = categoryId,
                    Description = caption,
                    OSPlatform = AnalyticsInfo.VersionInfo.DeviceFamily,
                    User = AppEnvironment.Instance.CurrentUser.ToDataContract(),
                    ThumbnailUrl =
                        sasContracts.FirstOrDefault(c => c.SasPhotoType == PhotoTypeContract.Thumbnail)?
                            .FullBlobUri.ToString(),
                    StandardUrl =
                        sasContracts.FirstOrDefault(c => c.SasPhotoType == PhotoTypeContract.Standard)?
                            .FullBlobUri.ToString(),
                    HighResolutionUrl =
                        sasContracts.FirstOrDefault(c => c.SasPhotoType == PhotoTypeContract.HighRes)?
                            .FullBlobUri.ToString()
                };

                var responsePhotoContract =
                    await _mobileServiceClient.InvokeApiAsync<PhotoContract, PhotoContract>("Photo",
                        photoContract,
                        HttpMethod.Post, 
                        null);

                return responsePhotoContract.ToDataModel();
            }
            catch (Exception e)
            {
                throw new ServiceException("UploadPhoto error", e);
            }
        }
开发者ID:AJ-COOL,项目名称:Win10DevStudy,代码行数:60,代码来源:ServiceClient.cs

示例5: UploadToBlobAsync

        internal async Task UploadToBlobAsync(String blobName, System.IO.Stream source)
        {
            var fileUploadRequest = new FileUploadRequest()
            {
                BlobName = blobName
            };

            var fileUploadResponse = await this.httpClientHelper.PostAsync<FileUploadRequest, FileUploadResponse>(
            GetRequestUri(this.deviceId, CommonConstants.BlobUploadPathTemplate, null),
            fileUploadRequest,
            ExceptionHandlingHelper.GetDefaultErrorMapping(),
            null,
            CancellationToken.None);

            string putString = String.Format("https://{0}/{1}/{2}{3}",
                fileUploadResponse.HostName,
                fileUploadResponse.ContainerName,
                fileUploadResponse.BlobName,
                fileUploadResponse.SasToken);

            var notification = new FileUploadNotificationResponse();

            try
            {
                // 2. Use SAS URI to send data to Azure Storage Blob (PUT)
                CloudBlockBlob blob = new CloudBlockBlob(new Uri(putString));
                var uploadTask = blob.UploadFromStreamAsync(source);
                await uploadTask;

                notification.CorrelationId = fileUploadResponse.CorrelationId;
                notification.IsSuccess = uploadTask.IsCompleted;
                notification.StatusCode = uploadTask.IsCompleted ? 0 : -1;
                notification.StatusDescription = uploadTask.IsCompleted ? null : "Failed to upload to storage.";

                // 3. POST to IoTHub with upload status
                await this.httpClientHelper.PostAsync<FileUploadNotificationResponse>(
                    GetRequestUri(this.deviceId, CommonConstants.BlobUploadStatusPathTemplate + "notifications", null),
                    notification,
                    ExceptionHandlingHelper.GetDefaultErrorMapping(),
                    null,
                    CancellationToken.None);
            }
            catch (Exception ex)
            {
                // 3. POST to IoTHub with upload status
                notification.IsSuccess = false;
                notification.StatusCode = -1;
                notification.StatusDescription = ex.Message;

                await this.httpClientHelper.PostAsync<FileUploadNotificationResponse>(
                    GetRequestUri(this.deviceId, CommonConstants.BlobUploadStatusPathTemplate + "notifications/" + fileUploadResponse.CorrelationId, null),
                    notification,
                    ExceptionHandlingHelper.GetDefaultErrorMapping(),
                    null,
                    CancellationToken.None);

                throw ex;
            }
        }
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:59,代码来源:HttpTransportHandler.cs

示例6: UploadContentToBlobStorage

 public override async Task<Uri> UploadContentToBlobStorage(string containerName, string fileName, string contentType, Stream fileContents, string sasTokenUri)
 {
     var storageCredentials = new StorageCredentials(sasTokenUri);
     var storageAccount = new CloudStorageAccount(storageCredentials, true);
     var blob = new CloudBlockBlob(null, null);
     blob.Properties.ContentType = contentType;
     await blob.UploadFromStreamAsync(fileContents);
     UriBuilder uriBuilder = new UriBuilder(sasTokenUri);
     uriBuilder.Query = null;
     uriBuilder.Fragment = null;
     return uriBuilder.Uri;
 }
开发者ID:paulbatum,项目名称:azure-mobile-services-resourcebroker,代码行数:12,代码来源:E2EBrokerTests.cs

示例7: ResizeImage

        private static async Task<string> ResizeImage(Stream streamInput, CloudBlockBlob blobOutput, ImageSize size)
        {
            streamInput.Position = 0;

            using (var memoryStream = new MemoryStream()) {
                // use a memory stream, since using the blob stream directly causes InvalidOperationException due to the way image resizer works
                var instructions = new Instructions(imageDimensionsTable[size]);
                var job = new ImageJob(streamInput, memoryStream, instructions, disposeSource: false, addFileExtension: false);

                // use the advanced version of resize so that we can get the content type
                var result = ImageBuilder.Current.Build(job);

                memoryStream.Position = 0;
                await blobOutput.UploadFromStreamAsync(memoryStream);

                var contentType = result.ResultMimeType;
                blobOutput.Properties.ContentType = contentType;
                blobOutput.SetProperties();

                return contentType;
            }
        }
开发者ID:lindydonna,项目名称:ContosoMoments,代码行数:22,代码来源:Functions.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStreamAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。