Dim connstr As String = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};", accountName, accountKey)
Dim storageAccount As CloudStorageAccount = CloudStorageAccount.Parse(connstr)
'//建立 Blob 服務用戶端
'//CloudBlobClient 類別可擷取 Blob 儲存體中儲存的容器和 Blob
Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient()
'//依照名稱找尋容器
Dim container As CloudBlobContainer = blobClient.GetContainerReference(containerName)
'//如果容器不存在就建立
container.CreateIfNotExists()
'//設定容器權限權限
container.SetPermissions(New BlobContainerPermissions With {.PublicAccess = access})
Dim tempF as new HttpPostedFileBase
Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference(tempF.FileName)
blockBlob.Properties.ContentType = tempF.ContentType
Dim ms As MemoryStream
tempF.InputStream.CopyTo(ms)
ms.Seek(0, SeekOrigin.Begin)
'使用MemoryStream 務必要使用seek 將指標回到起點
blockBlob.UploadFromStream(ms)
Dim Url As String = blockBlob.StorageUri.PrimaryUri.AbsoluteUri
'回傳檔案路徑
某支透過 WebClient 物件去呼叫第三方API的程式,突然有天無法使用 經過測試出現下列的錯誤 基礎連接已關閉: 傳送時發生未預期的錯誤。 InnerException : 驗證失敗,因為遠端群體已經關閉傳輸資料流。 原來是第三方的服務已經不支援 TLS 1.0 我方的程式是用.net Framework 4.0開發了 得強制讓webclient改用 TLS 1.1 或 TLS 1.2 感謝黑大提供解決方法 在程式中加入 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 的設定就解決了這個問題 WebClient wc = new WebClient(); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; 參考資料:暗黑執行緒
留言