AWS IOS SDK - 上传对象AWS S3(AWS ios SDK - uploading

2019-10-21 08:56发布

我试图按照在“上载对象”列出的步骤操作: http://docs.aws.amazon.com/mobile/sdkforios/developerguide/s3transfermanager.html

不过,我在转换的东西斯威夫特因为那是什么,我已经想出下面的代码我的整个应用程序编写,但是当我运行它没有被上传到我指定了水桶。 不幸的是我甚至不得到一个错误,这使得它很难解决 - 你可以看到下面,我试图打印任何错误到控制台,但myBFTask.error最终被空。 同时myBFTask.result也为空。 对于背景下,这个代码是所有里面的imagePickerController didFinishPickingMediaWithInfo。 到哪里寻找未来任何提示将不胜感激。

        var pickedURL:NSURL = info[UIImagePickerControllerMediaURL] as NSURL
        println("here's the url for the picked media: \(pickedURL)")

        //make a timestamp variable to use in the key of the video I'm about to upload
        let date:NSDate = NSDate()
        var unixTimeStamp:NSTimeInterval = date.timeIntervalSince1970
        var unixTimeStampString:String = String(format:"%f", unixTimeStamp)
        println("this is my unix timestamp as a string: \(unixTimeStampString)")

        var myTransferManagerRequest:AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()
        myTransferManagerRequest.bucket = "kikfli1.videolist"
        myTransferManagerRequest.key = "\(self.fbid)_\(unixTimeStampString)"
        myTransferManagerRequest.body = pickedURL

        var myBFTask:BFTask = BFTask()
        var myMainThreadBFExecutor:BFExecutor = BFExecutor.mainThreadExecutor()
        var myTransferManager:AWSS3TransferManager = AWSS3TransferManager()
        myTransferManager.upload(myTransferManagerRequest).continueWithExecutor(myMainThreadBFExecutor, withBlock: { (myBFTask) -> AnyObject! in
            println("I'm inside the completion block")
            if((myBFTask.result) != nil){
                println("upload was successful?")
            }else{
                println("upload didn't seem to go through..")
                var myError = myBFTask.error
                println("error: \(myError)")
            }
            return nil
        })

这里是被印到我的控制台:

用户选择了一个视频,提交!

这里的采摘媒体的网址:文件:xxxxxxxxxxxxxxx.MOV(显然是一个实际的文件路径)

这是我的UNIX时间戳为一个字符串:1417506382.414219

我完成块内

上传似乎没有经历..

误差为零

Answer 1:

你是不是传递AWSServiceConfigurationAWSS3TransferManager ,而且它造成的问题。 您需要更改下面一行:

var myTransferManager:AWSS3TransferManager = AWSS3TransferManager()

喜欢的东西

var myTransferManager:AWSS3TransferManager = AWSS3TransferManager.defaultS3TransferManager()

此外,您还需要设置默认的服务配置默认服务经理提前。



Answer 2:

我有一个类似的问题。 试图用致命错误上传时,应用程序崩溃:意外发现零而展开的可选值。

经过仔细检查该文件的路径存在我想通了,AWSS3TransferManager没有得到构建,因为我已经忘了设定的默认配置(3号线):

let credentialsProvider = AWSStaticCredentialsProvider(accessKey: AccesKey, secretKey: SecretKey)
let configuration = AWSServiceConfiguration(region: ServiceRegionType, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration


文章来源: AWS ios SDK - uploading objects to AWS S3