Guest User

Untitled

a guest
Jan 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public void UploadMultipleBlobs(List<string> filelocations, string containerName, AsyncCallback callback = null, string path = null)
  2. {
  3. try
  4. {
  5.  
  6. Parallel.ForEach(filelocations, fileLocation =>
  7. {
  8.  
  9. //File to Stream
  10. MemoryStream str = new MemoryStream();
  11. byte[] file = File.ReadAllBytes(fileLocation);
  12. str.Write(file, 0, file.Length);
  13. str.Seek(0, SeekOrigin.Begin);
  14.  
  15. //Operations
  16. if (callback == null)
  17. callback = new AsyncCallback(OnUploadCompleted);
  18. BlobRequestOptions blobRequestOptions = new BlobRequestOptions();
  19. blobRequestOptions.Timeout = new TimeSpan(1, 0, 0);
  20. blobRequestOptions.RetryPolicy = retry;
  21.  
  22. CloudBlob currentBlob = container.GetBlobReference(blobName);
  23. var result = currentBlob.BeginUploadFromStream(str, blobRequestOptions, callback, new Object[] { currentBlob, str });
  24.  
  25. currentBlob.EndUploadFromStream(result);
  26. });
  27.  
  28. }
  29. catch
  30. {
  31. throw;
  32. }
  33.  
  34. }
  35.  
  36. private void OnUploadCompleted(IAsyncResult result)
  37. {
  38. try
  39. {
  40. // Get array passed to callback
  41. Object[] states = (Object[])result.AsyncState;
  42.  
  43. var blob = (CloudBlob)states[0];
  44. var stream = (MemoryStream)states[1];
  45.  
  46. // End the operation
  47. //blob.EndUploadFromStream(result);
  48.  
  49. // Close the stream
  50. stream.Close();
  51. }
  52. catch
  53. {
  54. throw;
  55. }
  56. }
Add Comment
Please, Sign In to add comment