使用SAS上传的Swift 3 Azure Blob存储数据(图像,视频) [英] Swift 3 Azure Blob Storage Data (Image, Video) upload with SAS

查看:77
本文介绍了使用SAS上传的Swift 3 Azure Blob存储数据(图像,视频)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个有用的Swift 3 Azure Blob存储示例,可以用来上传一些数据(图像,视频).现在,我可以将记录插入到我的Mobile Service数据库中,然后在其中生成一个SAS,然后将其返回到我的iOS应用程序中.现在,我需要知道如何借助该SAS上传到Azure Blob存储.我已经成功地在Android上实现了同样的功能,并且可以正常工作,但是以某种方式,我很难找到有关"SWIFT"以及如何使用"SAS"的任何有用信息!

I'm searching for an useful Swift 3 Azure Blob Storage example which I could use to upload some data(image, video). For now, I can insert records into my Mobile Service database and there I generate a SAS and I get it back to my iOS application. Now I need to know how to upload to Azure Blob Storage with help of that SAS. I successfully implemented the same for Android and it works, but somehow I have troubles to find any useful information for "SWIFT" and how to use the "SAS"!

非常感谢如何在Swift中使用SAS上传代码的示例.

Any code examples how to upload with SAS in Swift are much appreciated.

此致

亚当

推荐答案

对于那些与我遇到的问题相同的人:这是Xcode 8和Swift 3中的一个有效示例.您必须包括"Azure Storage Client Library" "添加到您的项目中.

For those who have the same problem as I had: This is a working example in Xcode 8 and Swift 3. You have to include the "Azure Storage Client Library" into your project.

//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 !")
    })
    }

}

这篇关于使用SAS上传的Swift 3 Azure Blob存储数据(图像,视频)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆