2

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

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!

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

this is my unix timestamp as a string: 1417506382.414219

I'm inside the completion block

upload didn't seem to go through..

error nil

bkopp
  • 478
  • 1
  • 8
  • 20

2 Answers2

2

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

var myTransferManager:AWSS3TransferManager = AWSS3TransferManager()

to something like

var myTransferManager:AWSS3TransferManager = AWSS3TransferManager.defaultS3TransferManager()

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

Yosuke
  • 3,759
  • 1
  • 11
  • 21
  • 1
    that did the trick! I see now.. setting the default service configuration to the default service manager is done in the app delegate with the following code: let defaultServiceConfiguration = AWSServiceConfiguration(region: AWSRegionType.USWest1, credentialsProvider: credentialsProvider) AWSServiceManager.defaultServiceManager() .setDefaultServiceConfiguration(defaultServiceConfiguration) – bkopp Dec 02 '14 at 16:23
  • Hi Yosuke - is this something you'd be able to weigh in on? I've hit another roadblock and I am not sure my approach is correct.. http://stackoverflow.com/questions/27266916/aws-ios-sdk-http-post-request-for-elastic-transcoder-job – bkopp Dec 04 '14 at 01:04
2

I had a similar problem. The app crashed when trying to upload with fatal error: unexpectedly found nil while unwrapping an Optional value.

After double-checking that file exists at path I figured out that AWSS3TransferManager was not getting constructed, because I had forgot to set the default configuration (3rd line):

let credentialsProvider = AWSStaticCredentialsProvider(accessKey: AccesKey, secretKey: SecretKey)
let configuration = AWSServiceConfiguration(region: ServiceRegionType, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
Andrej
  • 7,266
  • 4
  • 38
  • 57