關於Azure Storage 的一點研究

2021-07-04 20:02:58 字數 2450 閱讀 5573

關於azure storage 的介紹和用c++去使用blob storage,可以參考下面這個官方資料:

運維給了乙個uri

https://.blob.core.chinacloudapi.cn/,乙個account_name和乙個account_key.

在嘗試往uri上傳檔案時,發現報錯,提示找不到對應位址。

使用的c++原始碼是從官方資料上直接copy的,如下:

// retrieve storage account from connection string.

azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// retrieve storage account from connection string.

azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// create the blob client.

azure::storage::cloud_blob_client blob_client = storage_account.create_cloud_blob_client();  

在仔細查閱官方資料和各種民間討論中,最終推斷出是uri的預設domain字尾的問題。具體來說,官方拼接的連線字串中,並沒有指定
core.windows.net  or

core.chinacloudapi.cn

推測應該是前者是預設的域字尾,而我需要使用的是中國地區的域字尾。
問題知道了,下一步就是如何解決了。
翻了很多官方和非官方的資料,都沒有說到該怎麼去設定這個值。
好在機智的我,通過使用如下所示的乙個視覺化管理工具,找到了一點線索。
視覺化工具 azure storage explorer 6 preview 3 (august 2014)(開源):

有了這個圖,更加證明了之前我的想法,問題就出現在這個storage endpoints domain。

遺憾的是,這裡的的ui並不能直接告訴我這個值對應的變數名是什麼。而試圖去檢視使用ui生成的連線字串,發現跟官方demo裡一致。

還在,這是個開源的工具。最終,經過對其c#原始碼的一番研究後,一切問題都得到了解決!

具體如下:

azure::storage::storage_credentials credential = azure::storage::storage_credentials(my_account_name,my_account_key);

azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account(

credential, endpoint_suffix, true

);

另外,通過分析原始碼的命名規則,推測出那個指定domain的變數值很可能應該長成這樣:endpointsuffix
於是,方案二也出現了:
// define the connection-string with your values.

至此,問題得到完美解決~
ps:不知道是不是我的開發環境問題(vs2013 & c++ azure sdk),官方demo的concurrency

::streams

::file_stream

::open_istream

方法我的程式裡提示沒有定義,進而無法使用upload_from_stream這個方法,
後來沒有正面去解決,而是使用了upload_from_file方法。

細說 Azure Storage 的冗餘策略

當我們想要把應用搬到雲端的時候,首先要關注的便是資料的安全性。當然所有的雲服務廠商都會對使用者資料承諾乙個非常高的安全性,但萬一出現意外呢?我們是不是還要有適當的應對方案?比如今年的3月8日晚間,azure 某個區域中的儲存幾乎全部不能訪問,持續達兩個多小時。當時最擔心的是 使用者的資料萬一丟掉怎麼...

如何搭建本地Azure Storage環境

開啟emulator,在控制台視窗中,鍵入以下命令,其中 是 sql server 例項的名稱。若要使用 localdb,請指定 localdb mssqllocaldb 作為 sql server 例項。a.azurestorageemulator.exe init server 也可以使用以下命...

關於this 的使用

如有不對的地方請大家指出,呵呵.this 的使用 1.this是指當前物件自己。當在乙個類中要明確指出使用物件自己的的變數或函式時就應該加上this引用。如下面這個例子中 public class a public static void main string args 執行結果 s hellow...