public static void SaveBlobLocally(string fileName, BlobProperties blobProperties, BlobContents blobContents)
 {
     if (blobContents != null && blobContents.AsBytes() != null && blobContents.AsBytes().Length > 0)
     {
         File.WriteAllBytes(fileName, blobContents.AsBytes());
     }//if
 }
Exemplo n.º 2
0
        internal static bool RefreshTextBlob(BlobContainer container, StringBlob stringBlob)
        {
            BlobContents   contents = new BlobContents(new MemoryStream());
            BlobProperties blob     = stringBlob.Blob;
            bool           modified = container.GetBlobIfModified(blob, contents, false);

            if (!modified)
            {
                return(false);
            }

            if (blob.ContentType == null)
            {
                throw new FormatException("No content type set for blob.");
            }

            ContentType blobMIMEType = new ContentType(blob.ContentType);

            if (!blobMIMEType.Equals(StringBlob.TextBlobMIMEType))
            {
                throw new FormatException("Not a text blob.");
            }

            stringBlob.Value = UnicodeEncoding.UTF8.GetString(contents.AsBytes());
            return(modified);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Read a UTF-8 encoded string.
        /// </summary>
        /// <param name="blobName">Name of the blob</param>
        /// <returns>Contents of the blob.</returns>
        internal static StringBlob GetTextBlob(BlobContainer container, string blobName)
        {
            BlobContents   contents = new BlobContents(new MemoryStream());
            BlobProperties blob     = container.GetBlob(blobName, contents, false);

            if (blob.ContentType == null)
            {
                throw new FormatException("No content type set for blob.");
            }

            ContentType blobMIMEType = new ContentType(blob.ContentType);

            if (!blobMIMEType.Equals(StringBlob.TextBlobMIMEType))
            {
                throw new FormatException("Not a text blob.");
            }

            return(new StringBlob
            {
                Blob = blob,
                Value = Encoding.UTF8.GetString(contents.AsBytes())
            });
        }