Я новичок в swift, и я хочу добавить более одного параметра файла в несколько частей, мой код выглядит так
func uploadWithAlamofirePDFAPI() {
var paradict = NSMutableDictionary()
let UrlPost = Url
var Patientidstring = String()
var Useridstring = String()
var SurgeryDateString = String()
var DischargeDateString = String()
var FundDisbusmentDateString = String()
var AmountString = String()
var PatientConditionString = String()
var IDString = String()
Patientidstring = String(self.patient_idfromservernew)
Useridstring = String(self.userId!)
SurgeryDateString = String(surgery_datefromservernew)
DischargeDateString = String(discharge_datefromservernew)
FundDisbusmentDateString = String(fund_disbursement_datefromservernew)
AmountString = String(txtAmount.text ?? "")
PatientConditionString = String(txtPatientCondition.text ?? "")
IDString = String(idservernewid)
paradict = ["patient_id":Patientidstring,"hospital_id":Useridstring,"surgery_date":SurgeryDateString,"discharge_date":DischargeDateString,"fund_disbursement_date":FundDisbusmentDateString,"amount":AmountString,"patient_condition":PatientConditionString,"id":IDString,"type":"2"]
print(paradict)
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(self.datavalue, withName: "bill", fileName: self.FileNamewithFormat, mimeType:"application/pdf")
for (key, value) in paradict {
print(key,value)
multipartFormData.append((value as AnyObject).data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue).rawValue)!, withName: key as! String)
}}, to: UrlPost, method: .post, headers: nil,
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.response { [weak self] response in
guard let strongSelf = self else {
return
}
debugPrint(response)
let alert = UIAlertController(title: nil, message: "Success", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
let MasterPatientListVC = self?.storyboard!.instantiateViewController(withIdentifier: "MasterPatientListVC") as! MasterPatientListVC
self?.navigationController?.pushViewController(MasterPatientListVC, animated: true)
}))
self?.present(alert, animated: true)
}
case .failure(let encodingError):
print("error:\(encodingError)")
let alert = UIAlertController(title: nil, message: encodingError as! String, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
}))
self.present(alert, animated: true)
}
})
}
Я хочу добавить еще 2 параметра здесь
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(self.datavalue, withName: "bill", fileName: self.FileNamewithFormat, mimeType:"application/pdf")
Когда я добавляю эту строку, отображается ошибка:
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(self.datavalue, withName: "bill", fileName: self.FileNamewithFormat, mimeType:"application/pdf"),(self.datavalueClinicSummary, withName: "Clinic", fileName: self.FileNamewithFormatClinicSummary, mimeType:"application/pdf")
и сообщение об ошибке:
Последовательные операторы в строке должны быть разделены ';'
Clinic
и Chemical
- это два параметра, которые я хочу добавить их так же, как я добавил bill
. Возможно ли это?
Если да, то как его добавить? Заранее спасибо!