简体   繁体   English

如何将视频从iOS相册上传到Azure Blob存储

[英]How to upload a video from iOS photo album to Azure Blob Storage

I am struggling with uploading videos from iOS photo album to Azure blob storage. 我正在努力将视频从iOS相册上传到Azure blob存储。 I am using AZSClient. 我正在使用AZSClient。

uploading images is straight forward, ie. 上传图片很简单。 I get the image 'Data' from PHAsset and then upload it to azure storage using AZSCloudBlockBlob.uploadFromData method 我从PHAsset获取图像“数据”,然后使用AZSCloudBlockBlob.uploadFromData方法将其上传到Azure存储

Can anyone guide me on how to upload a video to azure blob preferably in swift 谁能指导我如何最好快速地将视频上传到azure blob

There was a similar thread for this they used the bellow code, and they used the IOS library found here : 为此,他们使用了波纹管代码,并且使用了IOS库, 这里有一个类似的线程

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

}

I found the answer in this 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
            }
        })

once you get the Data object then you can use AZSCloudBlockBlob.uploadFromData to upload it to azure storage 一旦获得Data对象,就可以使用AZSCloudBlockBlob.uploadFromData将其上传到Azure存储

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM