如何将字节数组(即byte [])保存到Azure Blob存储中? [英] How do I save byte arrays i.e. byte[] to Azure Blob Storage?

查看:106
本文介绍了如何将字节数组(即byte [])保存到Azure Blob存储中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何保存流,但是我想获取该流并创建缩略图和其他大小的图像,但是我不知道如何将字节[]保存到Azure Blob存储.

I know how to save Streams, but I want to take that stream and create thumbnails and other sized images, but I don't know how to save a byte[] to the Azure Blob Storage.

这是我现在要保存的流:

This is what I'm doing now to save the Stream:

 // Retrieve reference to a blob named "myblob".
        CloudBlockBlob _blockBlob = container.GetBlockBlobReference("SampleImage.jpg");

        // upload from Stream object during file upload
        blockBlob.UploadFromStream(stream);

        // But what about pushing a byte[] array?  I want to thumbnail and do some image manipulation

推荐答案

它曾经在Storage Client库中(肯定是1.7版)-但是他们在2.0版中将其删除了

This used to be in the Storage Client library (version 1.7 for sure) - but they removed it in version 2.0

"所有上传和下载方法现在都是基于流的,例如FromFile, ByteArray,已删除文本重载."

"All upload and download methods are now stream based, the FromFile, ByteArray, Text overloads have been removed."

尽管围绕字节数组创建只读内存流非常轻巧:

Creating a read-only memory stream around the byte array is pretty lightweight though:

byte[] data = new byte[] { 1, 2, 3 };
using(var stream = new MemoryStream(data, writable: false)) {
    blockBlob.UploadFromStream(stream);
}

更新:UploadFromByteArray又回来了

MSDN文档 -根据我在来源中看到的信息代码,它在3.0版中又回来了,而在4.0版中仍然存在.

Update: UploadFromByteArray is back

MSDN documentation - from what I can tell in the source code, this came back for version 3.0 and is still there for version 4.0.

这篇关于如何将字节数组(即byte [])保存到Azure Blob存储中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆