/// <summary>Uploads a blob from a JSON FileWrapper instance</summary> /// <param name="file">The JSON wrapper with the image bytes in BASE64</param> /// <param name="containerName">Container to load to</param> /// <param name="blobName">Optional blob name. Random will be assigned if null</param> /// <returns></returns> public string UploadBlob(JSONFileWrapper file, string containerName, string blobName = null) { if (file == null || !file.IsValid) { return(null); } // set the local values byte[] fileData = Convert.FromBase64String(file.Data); this.FileName = file.Filename; this.ContentType = file.ContentType; this.ImageFile = new MemoryStream(fileData); return(this.UploadBlob(containerName, blobName)); }
/// <summary>Reads a file into a JSON wrapper conveted to BASE64 from an actual physical file source</summary> /// <param name="filePath">Local file path</param> /// <returns>Helper function</returns> public static JSONFileWrapper ReadFile(string filePath) { JSONFileWrapper results = new JSONFileWrapper(); FileInfo info = new FileInfo(filePath); if (!info.Exists) { return(results); } results.Filename = info.Name; results.ContentType = MimeTypeMap.GetMimeType(info.Extension); byte[] data = File.ReadAllBytes(filePath); results.Data = Convert.ToBase64String(data, Base64FormattingOptions.None); return(results); }
/// <summary>Gets a blob from Azure Storage BASE64 encoded and wrapped in JSON</summary> /// <param name="containerName">container name</param> /// <param name="blobName">blob name</param> /// <returns>The encoded blob with metadata</returns> public JSONFileWrapper GetWrappedBlob(string containerName, string blobName) { JSONFileWrapper results = new JSONFileWrapper(); // get the blob RawFileWrapper data = this.GetRawBlob(containerName, blobName); // validate if (!data.IsValid) { return(results); } // convert to BASE64 results.Data = Convert.ToBase64String(data.Data, Base64FormattingOptions.None); // get the properties results.ContentType = data.ContentType; results.Filename = data.Filename; return(results); }