Ejemplo n.º 1
0
        public async Task BlobStorage_sample1()
        {
            IBlobStorageProvider storage = StorageFactory.Blobs.AzureBlobStorage(
                _settings.AzureStorageName,
                _settings.AzureStorageKey,
                "container name");

            //upload it
            string content = "test content";

            using (var s = new MemoryStream(Encoding.UTF8.GetBytes(content)))
            {
                await storage.WriteAsync("someid", s);
            }

            //read back
            using (var s = new MemoryStream())
            {
                using (Stream ss = await storage.OpenReadAsync("someid"))
                {
                    await ss.CopyToAsync(s);

                    //content is now "test content"
                    content = Encoding.UTF8.GetString(s.ToArray());
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Opens the blob stream to read.
 /// </summary>
 /// <param name="id">Blob ID, required</param>
 /// <param name="cancellationToken"></param>
 /// <returns>Stream in an open state, or null if blob doesn't exist by this ID. It is your responsibility to close and dispose this
 /// stream after use.</returns>
 /// <exception cref="ArgumentNullException">Thrown when any parameter is null</exception>
 /// <exception cref="ArgumentException">Thrown when ID is too long. Long IDs are the ones longer than 50 characters.</exception>
 public Task <Stream> OpenReadAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_provider.OpenReadAsync(id, cancellationToken));
 }