0

I'm trying to download an image called "aaa.jpeg" in my s3 bucket using AWSMobileHubHelper. I found this function on their documentation site.

func downloadContent(content: AWSContent, pinOnCompletion: Bool) {
    content.downloadWithDownloadType( .Always, pinOnCompletion: pinOnCompletion, progressBlock: {(content: AWSContent?, progress: NSProgress?) -> Void in
            // Handle progress feedback
        }, completionHandler: {(content: AWSContent?, data: NSData?, error: NSError?) -> Void in
            if let error = error {
                print("Failed to download a content from a server.)")
                // Handle error here                    
                return
            }
            // Handle successful download here
            if let image = UIImage(data: data!){
                self.imageView = image
            }
        })
}

Once the download is successful (it Did, There is no error message), I'm trying to assign the image to an imageView. I can tell that the data has been downloaded successfully. I can print the data and see a familiar binary structure of an image. But for some reasons I can't assign the UIImage to the imageView. Because I can't convert the data to a UIImage.

I just want to know if this is the proper way to download image from s3 or am I missing something. Does "data" in the completion block carry the downloaded image? I can't seem to find any documentations on this.

Is this the correct function to use to download from S3?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Tommy
  • 979
  • 8
  • 15

1 Answers1

0

Yes, the data contains the actual image data. You can put the downloaded data in an UIImageViewController and it should open up fine. Also, this is demonstrated in a Sample App which can be downloaded from the Mobile Hub Console.

Rohan Dubal
  • 847
  • 5
  • 10