internal static void PutLargeString(BlobContainer container, StringBlob s, int repeatCount) { s.Blob.ContentType = StringBlob.TextBlobMIMEType.ToString(); RepeatedStream largeStream = new RepeatedStream( new MemoryStream(Encoding.UTF8.GetBytes(s.Value)), repeatCount); container.CreateBlob(s.Blob, new BlobContents(largeStream), true); Console.WriteLine("Successfully uploaded blob {0} at time {1}", s.Blob.Name, s.Blob.LastModifiedTime); }
/// <summary> /// Store a UTF-8 encoded string. /// </summary> private static void PutTextBlob( BlobContainer container, StringBlob s ) { container.CreateBlob( s.Blob, new BlobContents(Encoding.UTF8.GetBytes(s.Value)), true ); }
public void SaveImage(string id, string contentType, byte[] data) { BlobProperties properties = new BlobProperties(string.Format(CultureInfo.InvariantCulture, "image_{0}", id)); NameValueCollection metadata = new NameValueCollection(); metadata["Id"] = id; metadata["Filename"] = "userimage"; metadata["ImageName"] = "userimage"; metadata["Description"] = "userimage"; metadata["Tags"] = "userimage"; properties.Metadata = metadata; properties.ContentType = contentType; BlobContents imageBlob = new BlobContents(data); container.CreateBlob(properties, imageBlob, true); }
internal bool UploadStream(string blobName, Stream output, bool overwrite) { BlobContainer container = GetContainer(); try { output.Position = 0; //Rewind to start Log.Write(EventKind.Information, "Uploading contents of blob {0}", ContainerUrl + _PathSeparator + blobName); BlobProperties properties = new BlobProperties(blobName); return(container.CreateBlob(properties, new BlobContents(output), overwrite)); } catch (StorageException se) { Log.Write(EventKind.Error, "Error uploading blob {0}: {1}", ContainerUrl + _PathSeparator + blobName, se.Message); throw; } }
public bool CreateBlob(string containerName, BlobProperties blobProperties, BlobContents blobContents, bool overwrite) { BlobContainer container = BlobStorageType.GetBlobContainer(containerName); return(container.CreateBlob(blobProperties, blobContents, overwrite)); }
private string PostProcessVideo(UploadStatus status, decimal totalCount) { string resultMessage = String.Empty; string localFilePath = String.Empty; int counter = 0; //Setup the Azure Storage Container BlobContainer container = AzureUtility.GetAzureContainer(null); foreach (UploadedFile file in status.GetUploadedFiles()) { try { localFilePath = file.LocationInfo["fileName"].ToString(); //Save a skeleton record of the upload in the database Video vid = _videoRepository.New(); _videoRepository.AddVideoToUser(vid, User.Identity.Name); vid.Description = file.FormValues["fileDescription"]; vid.StartProcessingDate = DateTime.Now; vid.OriginalFileFormat = file.ContentType; vid.UploadSize = file.ContentLength; _videoRepository.Save(); Guid videoId = vid.Id; string encodedFilePath = FFmpegEncoder.EncodeToWmv(localFilePath, file.ContentType); if (!String.IsNullOrEmpty(encodedFilePath)) { string fileNameOnly = encodedFilePath.Substring(encodedFilePath.LastIndexOf("Upload") + 7); //TODO: Take a screenshot/Thumbnail of the video & upload it BlobProperties properties = AzureUtility.CollectBlobMetadata(file, fileNameOnly, User.Identity.Name); // Create the blob & Upload long finalSize = 0; using (FileStream uploadedFile = new FileStream(encodedFilePath, FileMode.Open, FileAccess.Read)) { BlobContents fileBlob = new BlobContents(uploadedFile); finalSize = fileBlob.AsStream.Length; container.CreateBlob(properties, fileBlob, true); } //Create the database record for this video vid = _videoRepository.GetById(videoId); vid.CreationDate = DateTime.Now; vid.FinalSize = finalSize; vid.Path = String.Format("{0}/{1}", container.ContainerName, fileNameOnly); _videoRepository.Save(); resultMessage = string.Format("Your video ({0}) is ready for you to use.", file.FormValues["fileDescription"]); //Delete the local copy of the encoded file System.IO.File.Delete(encodedFilePath); } else { resultMessage = "ERROR: video (" + file.FormValues["fileDescription"] + ") could not be converted to a recognizable video format."; } //Create a notification record so the user knows that processing is done for this video Notification note = _notificationRepository.New(); _notificationRepository.AddNotificationToUser(note, User.Identity.Name); note.UserNotified = false; note.Message = resultMessage; note.CreationDate = DateTime.Now; _notificationRepository.Save(); } catch (Exception ex) { resultMessage = string.Format("ERROR: we tried to process the video, {0}, but it did not finish. You might want to try again.", file.FormValues["fileDescription"]); //Create a notification record so the user knows that there was an error Notification note = _notificationRepository.New(); _notificationRepository.AddNotificationToUser(note, User.Identity.Name); note.UserNotified = false; note.Message = resultMessage; note.CreationDate = DateTime.Now; _notificationRepository.Save(); throw new Exception(resultMessage, ex); } finally { //Delete the local copy of the original file System.IO.File.Delete(localFilePath); counter++; } } return(resultMessage); }