iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 30
2
Cloud

Xamarin.Forms, ASP.NET Core WEB API搭配AZURE服務與資料庫服務整合應用實例系列 第 30

Day30 – Xamarin.Forms整合Google Map顯示打卡資料 Part2 Azure共用存取簽章 (SAS)

終於來到了最後一篇, 沒想到是來除錯的, Part1遇到的是Windows Azure Storage 8.0在Xamarin.Forms裡, 無法將檔案抓回來, 顯示在畫面上, Google了半天沒找到解決方式, 後來在Azure Storage File Service, 點選已上傳的檔案時, 會出現File properties的視窗, 看到了關鍵字URL如下紅框所示, 心想不會這麼簡單吧, 有提供URL的話, 那可以直接來拿用啦, 也不用Google半天找方法
http://ithelp.ithome.com.tw/upload/images/20170114/20103333j8TcFAJmxL.png

立馬貼到瀏覽器測試一下, 結果如下, 案情果然不單純啊
http://ithelp.ithome.com.tw/upload/images/20170114/20103333x9AmRgUzZC.png

錯誤是說HTTP header不正確, 意思是只要弄正確, 應該就可以順利讀取, 到目前為止至少有了個方向, 後來在Azure官方網站找到了底下這篇
https://docs.microsoft.com/zh-tw/azure/storage/storage-dotnet-shared-access-signature-part-1
其中的一段如下, 可能就是那道光啊
http://ithelp.ithome.com.tw/upload/images/20170114/20103333TVc3WbHndI.png

只要能生出問號後面的參數, 應該就能讀到檔案了, 根據這篇標題是共用存取簽章 (SAS), 所以到Azure Storage File Service找找看有無相關設定, 果然有找到Shared access signature, 設定完成後按下Generate SAS
http://ithelp.ithome.com.tw/upload/images/20170114/20103333FXTeTodsxi.png

此時Generate SAS下方就會出現問號後面的參數即所謂的SAS token
http://ithelp.ithome.com.tw/upload/images/20170114/201033337qBAwoOqb1.png

把SAS token貼回瀏覽器再測試一下, 檔案就可以下載了
http://ithelp.ithome.com.tw/upload/images/20170114/20103333tSgyfAYuqY.png

然後回到Visual Studio, 打開CheckInDetailPage.xaml.cs修改程式碼如下
http://ithelp.ithome.com.tw/upload/images/20170114/20103333zD8XiTUULl.png

終於可以正確顯示如下
http://ithelp.ithome.com.tw/upload/images/20170114/20103333H66DltiyeW.png

後記: 終於寫完了30篇, 每天都搞到半夜, 再下去應該會往生了/images/emoticon/emoticon17.gif, 在這一個半月來, 總算對ASP.NET CORE, Azure上的服務與Xamarin.Forms有初步的認識, 現在要寫個Mobile App或是架個雲端服務, 應該有概念了, Xamarin.Forms真是驗證了Run anywhere and debug anywhere啊, 之後有時間來架個Blog記錄個人實作心得好了/images/emoticon/emoticon12.gif~


上一篇
Day29 – Xamarin.Forms整合Google Map顯示打卡資料 Part1
下一篇
Day31 - 番外篇業務人員行程管理系統開發Android篇 Part1
系列文
Xamarin.Forms, ASP.NET Core WEB API搭配AZURE服務與資料庫服務整合應用實例32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言