public static BlobInfo putObjectInBlob(string containerName, string blobName, Object o) { string baseUri = ""; CloudBlobContainer blobContainer = initContainer(containerName, ref baseUri); bool didNotExistCreated = blobContainer.CreateIfNotExist(); byte[] blobContent = Serialize.serializeObject(o); var perms = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container // Blob (see files if you know the name) or Container (enumerate like a directory) }; blobContainer.SetPermissions(perms); // This line makes the blob public so it is available from a web browser (no magic needed to read it) string blobUriPath = blobName; // could also use paths, as in: “images/” + fileInfo.Name; CloudBlob blob = blobContainer.GetBlobReference(blobUriPath); blob.DeleteIfExists(); //write serialized object to our blob. blob.UploadByteArray(blobContent); blob.Properties.ContentType = MimeTypeName; // IMPORTANT: Mime Type here needs to match type of the uploaded file // e.g., *.png <=> image/png, *.wmv <=> video/x-ms-wmv (http://en.wikipedia.org/wiki/Internet_media_type) blob.SetProperties(); // REST call under the hood blob.Metadata["WhenFileUploadedUtc"] = DateTime.UtcNow.ToLongTimeString(); blob.SetMetadata(); // REST call under the hood string url = String.Format("{0}/{1}/{2}", baseUri, containerName, blobUriPath); BlobInfo toreturn = new BlobInfo(url, containerName, blobName); return(toreturn); }
public static BlobInfo putObjectInBlob(string containerName, string blobName, Object o) { string baseUri = ""; CloudBlobContainer blobContainer = initContainer(containerName,ref baseUri); bool didNotExistCreated = blobContainer.CreateIfNotExist(); byte[] blobContent = Serialize.serializeObject(o); var perms = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container // Blob (see files if you know the name) or Container (enumerate like a directory) }; blobContainer.SetPermissions(perms); // This line makes the blob public so it is available from a web browser (no magic needed to read it) string blobUriPath = blobName; // could also use paths, as in: “images/” + fileInfo.Name; CloudBlob blob = blobContainer.GetBlobReference(blobUriPath); blob.DeleteIfExists(); //write serialized object to our blob. blob.UploadByteArray(blobContent); blob.Properties.ContentType = MimeTypeName; // IMPORTANT: Mime Type here needs to match type of the uploaded file // e.g., *.png <=> image/png, *.wmv <=> video/x-ms-wmv (http://en.wikipedia.org/wiki/Internet_media_type) blob.SetProperties(); // REST call under the hood blob.Metadata["WhenFileUploadedUtc"] = DateTime.UtcNow.ToLongTimeString(); blob.SetMetadata(); // REST call under the hood string url = String.Format("{0}/{1}/{2}", baseUri, containerName, blobUriPath); BlobInfo toreturn = new BlobInfo(url, containerName, blobName); return toreturn; }