简体   繁体   English

Azure Blob存储是否有默认图像类型?

[英]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. 当我将jpg图像上传到Azure Blob存储时,再将其拉出时,它总是以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? 当我将扩展名从容器中拉出存储扩展名时,我可以在字节转换中轻松地将其转换回jpg,但是我可以安全地假定存储在Azure Blob存储中的任何图像类型都是png吗?

It is best not to assume that png is the default. 最好不要假设png是默认值。 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 但是我可以安全地假设Azure Blob存储中存储的任何图像类型都是以png格式完成的

As far as I know, blob storage doesn't have the default file type. 据我所知,blob存储没有默认的文件类型。 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. 如果设置,则斑点名称为xxx.jpg。 Then it will store the xxx.jpg in the blob storage. 然后它将xxx.jpg存储在Blob存储中。

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. 通过使用Storage Explorer,您可以在Blob存储中找到图像的类型。 It is brandotest.jpg. 这是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): 像这样(我将下载文件的路径设置为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. 结果将是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. 总而言之,您下载到本地或上传到Blob的文件类型取决于您使用代码获取或上传文件时的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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