コード例 #1
0
        public async Task <StorageModel> CreateBlobAsync(string fileName, string contents)
        {
            StorageModel model = null;

            var container = await GetCloudBlobContainerAsync();

            var blob = container.GetBlockBlobReference(fileName);

            using (var stream = new MemoryStream(Encoding.Default.GetBytes(contents), false))
            {
                await blob.UploadFromStreamAsync(stream);
            }

            model = new StorageModel(blob);

            return(model);
        }
コード例 #2
0
        public async Task <StorageModel> GetBlobAsync(string fileName)
        {
            StorageModel model     = null;
            var          container = await GetCloudBlobContainerAsync();

            var blob = container.GetBlockBlobReference(fileName);
            //Get the properties of the blob
            await blob.FetchAttributesAsync();

            model = new StorageModel(blob);
            var memStream = new MemoryStream();
            await blob.DownloadToStreamAsync(memStream);

            // Reset to beginning of stream
            memStream.Position = 0;
            model.Contents     = await new StreamReader(memStream).ReadToEndAsync();

            return(model);
        }