Upload videos to Amazon S3 in Swift

I tried uploading a video file to Amazon S3 in Swift, but I failed. Here is my code. Hope you can guide me.

@IBAction func uploadVideoBtnClicked(sender: AnyObject)
{
    //-- Add Amazon Video upload code

    var uploadRequest: AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()

    uploadRequest.bucket = "appFile"
    uploadRequest.key = "foldername/test.mov"

    //Move video file to the application folder so it can be read

    var savedVideoURLToBeUsed =  NSUserDefaults.standardUserDefaults().objectForKey("ThisIsTheVideoIWantToUse") as! String
    print("Video saved in Store: \(savedVideoURLToBeUsed)")

    var url: NSURL = self.videoPath

    uploadRequest.body = url

    print("URL: \(url)")

    let transferManager: AWSS3TransferManager = AWSS3TransferManager.defaultS3TransferManager()
    transferManager.upload(uploadRequest).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (AWSTask) -> AnyObject! in

        //Handle errors
        if AWSTask.error != nil {

            println("Error in uploading the video: \(AWSTask.error)")

            // Retrive information important for later downloading
        } else {
            println("Video upload successful..")
            var uploadResult: AnyObject! = AWSTask.result
            println("Upload result: \(uploadResult)")


        }
        return nil

    })

}

and I added the pod library file to an existing project.

+4
source share

Source: https://habr.com/ru/post/1624141/


All Articles