2017-04-03 134 views
-1

我正在尋找一個有用的Swift 3 Azure Blob存儲示例,我可以使用它來上傳一些數據(圖像,視頻)。現在,我可以將記錄插入到我的移動服務數據庫中,然後生成一個SAS,然後將其恢復到我的iOS應用程序。現在我需要知道如何在SAS的幫助下上傳到Azure Blob存儲。我成功地實現了Android的相同,它的工作原理,但不知何故,我有麻煩找到任何有用的信息「SWIFT」,以及如何使用「SAS」!Swift 3使用SAS上傳Azure Blob存儲數據(圖像,視頻)

任何代碼示例如何在Swift中使用SAS上傳非常感謝。

問候,

亞當

回答

2

對於那些因爲我有誰有同樣的問題:這是在Xcode 8和斯威夫特3.工作的例子。必須要「Azure存儲客戶端庫」包括成你的項目。

//Upload to Azure Blob Storage with help of SAS 
func uploadBlobSAS(container: String, sas: String, blockname: String, fromfile: String){ 

// If using a SAS token, fill it in here. If using Shared Key access, comment out the following line. 
var containerURL = "https://yourblobstorage.blob.core.windows.net/\(container)\(sas)" //here we have to append sas string: + sas 
    print("containerURL with SAS: \(containerURL) ") 
var container : AZSCloudBlobContainer 
var error: NSError? 

container = AZSCloudBlobContainer(url: NSURL(string: containerURL)! as URL, error: &error) 
if ((error) != nil) { 
print("Error in creating blob container object. Error code = %ld, error domain = %@, error userinfo = %@", error!.code, error!.domain, error!.userInfo); 
} 
else { 

    let blob = container.blockBlobReference(fromName: blockname) 
    blob.uploadFromFile(withPath: fromfile, completionHandler: {(NSError) -> Void in 
     NSLog("Ok, uploaded !") 
    }) 
    } 

} 
相關問題