Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void UploadMultipleBlobs(List<string> filelocations, string containerName, AsyncCallback callback = null, string path = null)
- {
- try
- {
- Parallel.ForEach(filelocations, fileLocation =>
- {
- //File to Stream
- MemoryStream str = new MemoryStream();
- byte[] file = File.ReadAllBytes(fileLocation);
- str.Write(file, 0, file.Length);
- str.Seek(0, SeekOrigin.Begin);
- //Operations
- if (callback == null)
- callback = new AsyncCallback(OnUploadCompleted);
- BlobRequestOptions blobRequestOptions = new BlobRequestOptions();
- blobRequestOptions.Timeout = new TimeSpan(1, 0, 0);
- blobRequestOptions.RetryPolicy = retry;
- CloudBlob currentBlob = container.GetBlobReference(blobName);
- var result = currentBlob.BeginUploadFromStream(str, blobRequestOptions, callback, new Object[] { currentBlob, str });
- currentBlob.EndUploadFromStream(result);
- });
- }
- catch
- {
- throw;
- }
- }
- private void OnUploadCompleted(IAsyncResult result)
- {
- try
- {
- // Get array passed to callback
- Object[] states = (Object[])result.AsyncState;
- var blob = (CloudBlob)states[0];
- var stream = (MemoryStream)states[1];
- // End the operation
- //blob.EndUploadFromStream(result);
- // Close the stream
- stream.Close();
- }
- catch
- {
- throw;
- }
- }
Add Comment
Please, Sign In to add comment