When I upload an jpg image to Azure Blob Storage, then pull it back out, it always comes back as a png. Is this a safe to assume default? I could not find any documentation. I can easily convert it back to a jpg in my byte conversion as I store the extension when I pull it out of the container, but can I safely assume any image type that is stored in Azure Blob Storage is done as a png?
2 Answers
but can I safely assume any image type that is stored in Azure Blob Storage is done as a png
As far as I know, blob storage doesn't have the default file type. It contains a content-type which could tell the user the file's content type is. If you set the blob name is xxx.jpg. Then it will store the xxx.jpg in the blob storage.
Here is an example.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("connection string");
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
CloudBlockBlob blockBlob = container.GetBlockBlobReference("brandotest.jpg");
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"D:\1.PNG"))
{
blockBlob.UploadFromStream(fileStream);
}
Result:
By using storage explorer, you could find the image's type in the blob storage. It is brandotest.jpg.
I guess you set the download image file's type when you use codes to download it.
Like this(I set the download file's path is myfile.png):
CloudBlockBlob blockBlob = container.GetBlockBlobReference("brandotest.jpg");
// Save blob contents to a file.
using (var fileStream = System.IO.File.OpenWrite(@"D:\authserver\myfile.png"))
{
blockBlob.DownloadToStream(fileStream);
}
The result will be myfile.png.
All in all, the file's type you have download to local or upload to the blob is according to your set when you using codes to get or upload it.