0
votes

I am struggling with uploading videos from iOS photo album to Azure blob storage. I am using 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

Can anyone guide me on how to upload a video to azure blob preferably in swift

2
Valid question and someone who is working in this space can easily understand the exact question you're asking. I don't know why some have to downvote questions like these. I've upvoted coz my question is exactly the same in objective c.Curious101

2 Answers

0
votes

There was a similar thread for this they used the bellow code, and they used the IOS library found 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 !")
    })
    }

}
0
votes

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