gpt4 book ai didi

swift - 如何快速上传通过 alamofire 从手机中选取的 pdf 和图像(无论选择哪一个)文件

转载 作者:行者123 更新时间:2023-11-30 11:10:41 24 4
gpt4 key购买 nike

这是选择文件时调用的函数。需要发送参数。请求的url就是服务器的url。

func Upload()
{
var request = URLRequest(url: URL(string: Constants.mainApi +
Constants.ADD_CLAIM_DOC)!)
request.httpMethod = "POST"
request.setValue("application/x-www-form-urlencoded",
forHTTPHeaderField: "Content-Type")
request.setValue("Bearer \(userToken)", forHTTPHeaderField:
"Authorization")

let parameters = ["FileName": myURL as AnyObject,
"ClaimID":self.ClaimID!
] as [String : Any]
}

最佳答案

func UploadDoc(){

    let URL1 = URL(string: Constants.mainApi + Constants.ADD_CLAIM_DOC)!

let filename = myURL?.lastPathComponent
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(self.myURL!, withName: filename)
multipartFormData.append((self.ClaimID?.data(using: .utf8)!)!, withName: "ClaimID")

},
to: URL1,
method : .post,
headers : Constants.headers,
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)


case .failure(let encodingError):
print(encodingError)

})


}

关于swift - 如何快速上传通过 alamofire 从手机中选取的 pdf 和图像(无论选择哪一个)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52204634/

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