Practice - Azure Blob

Practice - Azure storage blob

Azure storage types

Azure currently support storage types include: Blob, File, Table and Queue.


Snip20180611_1.png

Azure blob structure

Blob was used to store unstructured objects such as files, images and videos.


blob_storage.jpg

You can think it's three level hierarchy: storage account -> container -> blob.

storage account: It's a name space which was used for access control and payment.

Container: silimar to AWS bucket in S3, you can think it's directory to orgnize your files.

Access URL:

http://<account>.blob.core.windows.net/<container>/<filename>

example:
http://nick.blob.core.windows.net/pictures/image1.png

Upload files to blob

All steps go through Azure CLI.

Create storage account

az storage account create -g resourc_group_name -n storage_account_name

$ az storage account create -g RoyResourceGroup -n royrepoblob
{
  "accessTier": null,
  "creationTime": "2018-06-08T07:08:56.652151+00:00",
  "customDomain": null,
  "enableHttpsTrafficOnly": false,
  "encryption": {
    "keySource": "Microsoft.Storage",
    "keyVaultProperties": null,
    "services": {
      "blob": {
        "enabled": true,
        "lastEnabledTime": "2018-06-08T07:08:56.714690+00:00"
      },
      "file": {
        "enabled": true,
        "lastEnabledTime": "2018-06-08T07:08:56.714690+00:00"
      },
      "queue": null,
      "table": null
    }
  },
  "id": "/subscriptions/xxx/resourceGroups/RoyResourceGroup/providers/Microsoft.Storage/storageAccounts/royrepoblob",
  "identity": null,
  "kind": "Storage",
  "lastGeoFailoverTime": null,
  "location": "japanwest",
  "name": "royrepoblob",
  "networkRuleSet": {
    "bypass": "AzureServices",
    "defaultAction": "Allow",
    "ipRules": [],
    "virtualNetworkRules": []
  },
  "primaryEndpoints": {
    "blob": "https://royrepoblob.blob.core.windows.net/",
    "file": "https://royrepoblob.file.core.windows.net/",
    "queue": "https://royrepoblob.queue.core.windows.net/",
    "table": "https://royrepoblob.table.core.windows.net/"
  },
  "primaryLocation": "japanwest",
  "provisioningState": "Succeeded",
  "resourceGroup": "RoyResourceGroup",
  "secondaryEndpoints": {
    "blob": "https://royrepoblob-secondary.blob.core.windows.net/",
    "file": null,
    "queue": "https://royrepoblob-secondary.queue.core.windows.net/",
    "table": "https://royrepoblob-secondary.table.core.windows.net/"
  },
  "secondaryLocation": "japaneast",
  "sku": {
    "capabilities": null,
    "kind": null,
    "locations": null,
    "name": "Standard_RAGRS",
    "resourceType": null,
    "restrictions": null,
    "tier": "Standard"
  },
  "statusOfPrimary": "available",
  "statusOfSecondary": "available",
  "tags": {},
  "type": "Microsoft.Storage/storageAccounts"
}

Create container

az storage container create -n container_name —account-name storage_account_name

$ az storage container create -n src --account-name royrepoblob
{
  "created": true
}

Upload single file

az storage blob upload -f path_to_file --account-name storage_account_name -c container_name -n file_name_in_blob

[centos@roy-ansible src]$ az storage blob upload -f ./jdk-8u162-linux-x64.tar.gz --account-name royrepoblob  -c src -n jdk-8u162-linux-x64.tar.gz
Finished[#############################################################]  100.0000%
{
  "etag": "\"0x8D5CD10DA4C33B8\"",
  "lastModified": "2018-06-08T07:24:20+00:00"
}

Set access permission for container

az storage container set-permission --name container_name --account-name storage_account_name --public-access public_option

$ az storage container set-permission --name src --account-name royrepoblob --public-access blob
{
  "etag": "\"0x8D5CD17CE5743B7\"",
  "lastModified": "2018-06-08T08:14:07+00:00"
}

Note for public_option:

--public-access

Specifies whether data in the container may be accessed publically. By default, container data is private ("off") to the account owner. Use "blob" to allow public read access for blobs. Use "container" to allow public read and list access to the entire container.

accepted values: blob, container, off

[Note] container permission: anonymously read and list only be available for application not for web browser.

Verify if the new uploaded file can be access

The default endpoint for Blob storage is storage-account-name.blob.core.windows.net

Try:

wget http://royrepoblob.blob.core.windows.net/src/jdk-8u162-linux-x64.tar.gz

Upload batch files

az storage blob upload-batch -s local_path -d blob_container —account-name storage_account_name

az storage blob upload-batch -s ./ -d local --account-name royrepoblob

Change blob file

Files in blob cannot be edit directly, you should re-upload the file to overwrite it. (the same command as upload single file)

Further more: access private file in blob

Files in blob are set private access permission by default, you can access it by using shared access signatures(SAS).

You can generate SAS in storage account page via Azure web portal as below:

SAS_azure_set.png
Verify

You will fail to download the file in http://royrepoblob.blob.core.windows.net/src/test.txt since it's private file. You should change it to use https and add SAS token at end of the url. (get SAS in above web page)

It looks like:

 https://royrepoblob.blob.core.windows.net/src/test.txt?sv=2018-03-28&ss=b&srt=co&sp=rl&se=2019-06-08T10:44:53Z&st=2018-12-28T02:44:53Z&spr=https&sig=7oEcPe7FtwatpNYlkepy0DJF0pdb7TBUTaMG97n5pUs%3D

Reference:

Quickstart: Upload, download, and list blobs using the Azure CLI
Using the Azure CLI with Azure Storage

Generate SAS Token for Blob in Azure Storage

Using shared access signatures (SAS)

Authorizing access to Azure Storage

az storage blob command

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末侥钳,一起剝皮案震驚了整個(gè)濱河市柄错,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌售貌,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,290評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件颂跨,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡恒削,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,107評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門躯砰,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人携丁,你說我怎么就攤上這事。” “怎么了痕慢?”我有些...
    開封第一講書人閱讀 156,872評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)掖举。 經(jīng)常有香客問我,道長(zhǎng)塔次,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,415評(píng)論 1 283
  • 正文 為了忘掉前任名秀,我火速辦了婚禮励负,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘匕得。我一直安慰自己继榆,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,453評(píng)論 6 385
  • 文/花漫 我一把揭開白布汁掠。 她就那樣靜靜地躺著略吨,像睡著了一般。 火紅的嫁衣襯著肌膚如雪考阱。 梳的紋絲不亂的頭發(fā)上翠忠,一...
    開封第一講書人閱讀 49,784評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音乞榨,去河邊找鬼秽之。 笑死,一個(gè)胖子當(dāng)著我的面吹牛吃既,可吹牛的內(nèi)容都是我干的考榨。 我是一名探鬼主播,決...
    沈念sama閱讀 38,927評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼态秧,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼董虱!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起申鱼,我...
    開封第一講書人閱讀 37,691評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤愤诱,失蹤者是張志新(化名)和其女友劉穎圣勒,沒想到半個(gè)月后喂柒,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體狡刘,經(jīng)...
    沈念sama閱讀 44,137評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡厦幅,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,472評(píng)論 2 326
  • 正文 我和宋清朗相戀三年仗考,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了磺箕。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片囤萤。...
    茶點(diǎn)故事閱讀 38,622評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡浑此,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出对人,到底是詐尸還是另有隱情谣殊,我是刑警寧澤,帶...
    沈念sama閱讀 34,289評(píng)論 4 329
  • 正文 年R本政府宣布牺弄,位于F島的核電站姻几,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏势告。R本人自食惡果不足惜蛇捌,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,887評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望咱台。 院中可真熱鬧络拌,春花似錦、人聲如沸回溺。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,741評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)瓮恭。三九已至屯蹦,卻和暖如春绳姨,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背脑蠕。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來泰國(guó)打工谴仙, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留碾盐,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,316評(píng)論 2 360
  • 正文 我出身青樓掀虎,卻偏偏與公主長(zhǎng)得像烹玉,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子县忌,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,490評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容