SQL azure中的参考blob存储数据

Pau*_*ter 8 azure azure-storage azure-storage-blobs azure-sql-database

我只是想知道是否可以在SQL Azure表列中引用azure blob存储数据?

例如,假设我有一个表叫用户在我的SQL Azure数据库,在表中的一列UserImage和,而不是创建UserImage一个varbinary(MAX),并在表中的图像数据直接存储,我反而想存储的图像数据在blob存储中,获取对blob数据的引用并将该引用存储在数据库的UserImage(varchar??)列中,然后以某种方式,当从Users表中读取行时,使用引用从blob存储中访问关联的图像数据那个数据.

我问这个是因为blob存储使用比直接在SQL Azure中的二进制/ blob数据便宜得多.

小智 6

您应该只将图像存储在SQL Azure中,这是一个简短的片段,用于将图像上传到Blob存储并获取其Url:

    // Fake stream that contains your image to upload
    Stream data; 

    // Get a handle on account, create a blob service client and get container proxy
    var container = Account.CreateCloudBlobClient()
                        .GetContainerReference("my-fake-container");

    // Create a blob in container and upload image bytes to it
    var blob = container.GetBlobReference("my-fake-id");
    blob.Properties.ContentType = "image/jpeg";
    blob.UploadFromStream(data);

    // Get your iage Url in the Blob storage
    var imageUrl = blob.Uri;
Run Code Online (Sandbox Code Playgroud)

您现在只需要将imageUrl存储在您的行中.


Igo*_*rek 5

您应该能够将图像的 URL 存储在 SQL Azure 中,并让客户端程序解析 URL 并显示来自 URL 的图像。

我想不出任何让 SQL Azure 直接转到 Blob 存储的方法,我也认为不需要这样做,因为大多数客户端程序将能够使用 URL 以及使用 BLOB。