gpt4 book ai didi

ios - 如何在Swift中的multipartFormData中添加2个以上文件参数

转载 作者:行者123 更新时间:2023-12-01 18:35:34 24 4
gpt4 key购买 nike

我是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")

错误消息是:

行上的连续语句必须用';'分隔
ClinicChemical是我要像添加 bill一样添加两个参数。可能吗?

如果是,那我该如何添加呢?
提前致谢!

最佳答案

尝试,

Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(self.datavalue, withName: "bill", fileName: self.FileNamewithFormat, mimeType:"application/pdf")
multipartFormData.append(self.datavalueClinicSummary, withName: "Clinic", fileName: self.FileNamewithFormatClinicSummary, mimeType:"application/pdf")
}

您的陈述不正确。

关于ios - 如何在Swift中的multipartFormData中添加2个以上文件参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59945903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com