How to upload to S3 bucket taking a photo with the iOS Camera

0 votes

I am trying to use the AWS S3 bucket to store user photos from when they have taken them from their phones. I right now have my code set up to the point where the user is able to take a photo of something and have that show up on the UIImageView.

The issue I am encountering is that I have no clue how to store it on the S3 bucket, I have code right now that is able to store a specified photo the bucket, but not really code that is able to store a photo that is taken from the camera.

Take Photo code

    @IBAction func takePhoto(_ sender: Any) {
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerController.SourceType.camera
            imagePicker.allowsEditing = false
            self.present(imagePicker, animated: true, completion: nil)

        }

    }
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
            takenPhoto.contentMode = .scaleToFill
            takenPhoto.image = pickedImage
            print(takenPhoto.image = pickedImage)
        }
        picker.dismiss(animated: true, completion: nil)



    }

AWS S3 Bucket Code

    @IBAction func uploadFile(_ sender: Any) {
        uploadFile(with: "eartj", type: ".jpeg")

    }


    func uploadFile(with resource: String, type: String){
        let key = "\(resource),\(type)"
        let imagePath = Bundle.main.path(forResource: resource, ofType: type)!
        let imageUrl = URL(fileURLWithPath: imagePath)

        let request = AWSS3TransferManagerUploadRequest()!

        request.bucket = "wuuurktest"
        request.key = key
        request.body = imageUrl
        request.acl = .publicReadWrite

        let transferManager = AWSS3TransferManager.default()

        transferManager.upload(request).continueWith(executor: AWSExecutor.mainThread()) { (task) -> Any? in
            if let error = task.error {
                print(error)

            }

            if task.result != nil {
                print("Uploaded File")

            }

            return nil

        }

    }


 

Nov 30, 2022 in Mobile Development by gaurav
• 23,260 points
695 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Mobile Development

0 votes
0 answers

How to fetch the width and height of a programatically added view in Swift/ iOS?

I have added a UIView and a ...READ MORE

Nov 10, 2022 in Mobile Development by gaurav
• 23,260 points
1,104 views
0 votes
0 answers

How to receive single tap and hold Remote-Control Event with iOS

I'm looking for my app to listen ...READ MORE

Nov 8, 2022 in Mobile Development by gaurav
• 23,260 points
440 views
0 votes
0 answers

How to login to a site using POST request? (Swift,iOS)

I want to create an iOS Application ...READ MORE

Nov 9, 2022 in Mobile Development by gaurav
• 23,260 points
687 views
0 votes
0 answers

How to get original image when we zoom in and zoom out the image in ios

Hi i am beginner in ios and ...READ MORE

Nov 17, 2022 in Mobile Development by gaurav
• 23,260 points
679 views
0 votes
1 answer

How to get the user's country calling code in iOS?

Import Statement : #import<CoreTelephony/CTCarrier.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h> you can get country ...READ MORE

answered Dec 15, 2022 in Mobile Development by gaurav
• 23,260 points
1,201 views
0 votes
0 answers

How to receive single tap and hold Remote-Control Event with iOS?

I'm looking for my app to listen ...READ MORE

Nov 30, 2022 in Mobile Development by gaurav
• 23,260 points
298 views
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,020 points
5,958 views
–1 vote
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,020 points
5,204 views
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,820 points
2,868 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP