I want to upload pictures to the server using Alamofire.
I have changed the selected photo from imagePicker to jpegData and used it in append of MultipartFormData.
When sending a communication, the memory of the app increases rapidly and when using debugPrint, a huge amount of code is extracted.
What is the problem?
I put my code below.
let header: HTTPHeaders = [
"Content-Type":"multipart/form-data; boundary=\(boundary)",
"access_token":"\(UserDefaults.standard.string(forKey: "token")!)"
]
AF.upload(multipartFormData: { (MultipartFormData) in
MultipartFormData.append(self.imageData, withName: "img", fileName: "img", mimeType: "img/jpeg")
MultipartFormData.append((self.titleTextField.text?.data(using: .utf8))!, withName: "content")
}, to: "https://httpbin.org/post", method: .post, headers: header).responseJSON { (result) in
debugPrint(result)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let pickedImage = info[.originalImage] as? UIImage else { return }
imageView.image = pickedImage
image = pickedImage
imageData = pickedImage.jpegData(compressionQuality: 0)
imageViewNilLbl.isHidden = true
picker.dismiss(animated: true, completion: nil)
}