コード例 #1
0
        private CloudBlockBlob getBlob(Uri uri)
        {
            var             storageAccount = CloudStorageAccount.Parse(DocConstants.Get().ConnectionString);
            CloudBlobClient blobClient     = storageAccount.CreateCloudBlobClient();
            ICloudBlob      blob           = blobClient.GetBlobReferenceFromServer(uri);

            return(blob as CloudBlockBlob);
        }
コード例 #2
0
        private CloudBlobContainer getBlobContainer(string folderName, bool createIfNotExists = true, bool setPublic = true)
        {
            var                storageAccount = CloudStorageAccount.Parse(DocConstants.Get().ConnectionString);
            CloudBlobClient    blobClient     = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer blobContainer  = blobClient.GetContainerReference(folderName);

            if (createIfNotExists)
            {
                blobContainer.CreateIfNotExists();
            }

            if (setPublic)
            {
                setPublicAccess(blobContainer);
            }

            return(blobContainer);
        }
コード例 #3
0
        /// <summary>
        /// Gets content of the blob
        /// </summary>
        /// <param name="fileName">The name of the blob, or the absolute URI to the blob</param>
        /// <param name="folderName">The name of the blob container</param>
        /// <param name="type">The type of the blob's content</param>
        /// <returns>Streams with blob's content</returns>
        public Stream Load(string fileName, string folderName, out string type)
        {
            var                storageAccount = CloudStorageAccount.Parse(DocConstants.Get().ConnectionString);
            CloudBlobClient    blobClient     = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer blobContainer  = blobClient.GetContainerReference(folderName);

            Stream file = null;

            type = string.Empty;

            string res = string.Format(PATH, folderName, fileName);

            var blob = blobContainer.GetBlockBlobReference(res);

            if (blob.Properties.Length > 0)
            {
                blob.FetchAttributes();
                type = blob.Properties.ContentType;
                file = blob.OpenRead();
            }

            return(file);
        }