简体   繁体   中英

Is there a default image type for Azure Blob Storage?

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?

It is best not to assume that png is the default. I think it depends on your upload mechanism and the name you give for the file during the upload process.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM