Upload Image from UIImagePickerController using Alamofire

Tram Ho

Firstly.

Uploading from UIImagePickerController you will need a data file from Image Picker.

First you will need UIImagePickerControllerDelegate , UINavigationControllerDelegate and add Privacy-Photo Library Usage Description in info.plist file.

Before calling the imagePickerController function, you need to add the UIImagePickerController delegate inside your function. For example, I have a handleProfilePicker function

After adding the delegate, you can call the function imagePickerController didFinishPickingMediaWithInfo . This function is to keep the image file from your photo library

I had a sample code to complete the picker to select the image from the Image processing is value and not edit edit:

After successfully selecting images from the picker, the second thing is to know the data images. UIImageJPEGRepresentation will return the selected image from the picker to a JPEG image and compress it

Parameters

We will upload the image from the picker when the asscess token is required


Make sure your key is in the parameter with the server and of course the withName parameter in multipartFormData is the same. I hope you will successfully upload photos from the picker with Alamofire

Source: https://medium.com/@hanifsgy/alamofire-multipart-with-parameters-upload-image-from-uiimagepickercontroller-swift-a4abada24ae

Share the news now

Source : Viblo