how to upload an image using multipart/form-data in Swift With Moya
my code
var multipartBody: [MultipartFormData]? {
switch self {
case .registerWith(let registrationObject ):
if let profileImageData = registrationObject.profileImageData{
return [MultipartFormData(provider: .data(profileImageData), name: "profile_picture", fileName: "\(registrationObject.phone).jpg",
mimeType: "image/jpeg")]
}
return nil
default:
return nil
}
}
var task: Task {
switch self {
case .registerWith:
if let multipartBody = multipartBody {
return .upload(.multipart(multipartBody))
}else{
return .request
}
default:
return .request
}
}
but I need to send the imageData in body With key "profileImage"
1- Put files you want to upload in MultipartFormData Array
2- make task type of this method is uploadMultipart
1- Put files you want to upload in MultipartFormData Array
2- Add a provider of multipartBody to request's body of the method you need it
3- make task type of this method is upload