我正在努力将视频从iOS相册上传到Azure blob存储。我正在使用AZSClient。
上传图片很简单,即。我得到的图像'数据'从PHAsset,然后使用AZSCloudBlockBlob.uploadFromData方法将其上传到Azure存储
任何人都可以指导我如何将视频上传到azure blob,最好是在swift中
答案 0 :(得分:0)
有一个类似的thread,他们使用了下面的代码,他们使用了找到的IOS库 here :
//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 !")
})
}
}
答案 1 :(得分:0)
我在thread
中找到了答案let manager = PHImageManager.default()
manager.requestAVAsset(forVideo: asset, options: nil, resultHandler: { (avasset, audio, info) in
if let avassetURL = avasset as? AVURLAsset {
guard let video = try? Data(contentsOf: avassetURL.url) else {
return
}
videoData = video
}
})
获得Data对象后,您可以使用AZSCloudBlockBlob.uploadFromData将其上传到Azure存储