Swift   发布时间:2022-04-29  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了视频上传到Swift中的Amazon S3大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已尝试在 Swift中将视频文件上传到Amazon S3,但我失败了.这是我的代码.我希望你能引导我.

@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

    })

}

我在现有项目中添加了pod库文件.

解决方法

在uploadVideo中传递视频的URL

func uploadVideo(fileUrl : URL){

  let newKey = "video/1.mov"

  let uploadrequest = AWSS3TransfeRMANagerUploadrequest()
  uploadrequest?.body = fileUrl as URL
  uploadrequest?.key = newKey
  uploadrequest?.bucket = "YourBucketName"
  uploadrequest?.acl = AWSS3ObjectCAnnedACl.publicRead 
  uploadrequest?.contentType = "movie/mov"

  uploadrequest?.uploadProgress = { (bytesSent,@R_370_10586@lBytesSent,@R_370_10586@lBytesExpectedToSend) -> Void in
      DispatchQueue.main.async(execute: {
          let amountUploaded = @R_370_10586@lBytesSent // To show the updating data status in label.
          print(amountUploaded)
      })
  }

  let transfeRMANager = AWSS3TransfeRMANager.default()
  transfeRMANager.upload(uploadrequest!).conTinueWith(executor: AWSExecutor.mainThread(),block: { (task) in
      if task.error != nil {
          print(task.error.debugDescription)
      } else {
          // Do something with your result.
          print("done")
      }
      return nil
  })

}

大佬总结

以上是大佬教程为你收集整理的视频上传到Swift中的Amazon S3全部内容,希望文章能够帮你解决视频上传到Swift中的Amazon S3所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。