AWS IOS SDK - 上传对象AWS S3 [英] AWS ios SDK - uploading objects to AWS S3

查看:472
本文介绍了AWS IOS SDK - 上传对象AWS S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想跟随下载对象列出的步骤操作:的http://docs.aws.amazon.com/mobile/sdkforios/developerguide/s3transfermanager.html

I'm trying to follow the steps listed here under "Upload an Object": http://docs.aws.amazon.com/mobile/sdkforios/developerguide/s3transfermanager.html

不过,我将事情交给斯威夫特,因为这是我的整个应用程序是用,我已经拿出以下code,但是当我运行它没有被上传到我指定的水桶。不幸的是我甚至不得到一个错误,这使得它很难解决 - 你可以看到下面我试图打印任何错误控制台,但myBFTask.error最终被空。与此同时myBFTask.result也为空。对于背景下,这一code是所有里面的imagePickerController didFinishPickingMediaWithInfo。在哪里看接下来的任何提示将不胜AP preciated。

However, I'm converting things over to Swift because that's what my whole application is written in. I've come up with the following code, but when I run it nothing gets uploaded to the bucket I specified. Unfortunately I don't even get an error, which makes it hard to troubleshoot - you can see below that I'm trying to print any error to the console, but myBFTask.error ends up being null. At the same time myBFTask.result is also null. For context, this code is all inside the imagePickerController didFinishPickingMediaWithInfo. Any tips on where to look next would be greatly appreciated.

        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
        })

下面就是将要打印到我的控制台:

Here is what gets printed to my console:

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

the user picked a video for submission!

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

here's the url for the picked media: file:xxxxxxxxxxxxxxx.MOV (obviously an actual file path)

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

this is my unix timestamp as a string: 1417506382.414219

我在完成块内

上传似乎没有经历..

upload didn't seem to go through..

误差为零

推荐答案

您没有通过 AWSServiceConfiguration AWSS3TransferManager ,并且它导致了问题。您需要更改以下行:

You are not passing AWSServiceConfiguration to AWSS3TransferManager, and it's causing the issue. You need to change the following line:

var myTransferManager:AWSS3TransferManager = AWSS3TransferManager()

要像

var myTransferManager:AWSS3TransferManager = AWSS3TransferManager.defaultS3TransferManager()

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

Also, you need to set the default service configuration to the default service manager in advance.

这篇关于AWS IOS SDK - 上传对象AWS S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆