gpt4 book ai didi

ios - Alamofire multipartFormData 上传不发送数据

转载 作者:搜寻专家 更新时间:2023-10-31 08:33:11 26 4
gpt4 key购买 nike

我正在尝试使用 Alamofire 上传图像,但服务器未获取图像。这是我上传的代码:

Alamofire.upload(Router.UpdateUserAvatar,
multipartFormData: { (multipartFormData) -> Void in
let compressionQuality: CGFloat = 0.8
guard let imageData = UIImageJPEGRepresentation(image, compressionQuality) else {
print("Unable to get JPEG representation for image \(image)")
callCompletion()
return
}
multipartFormData.appendBodyPart(data: imageData, name: ParameterKey.Avatar, mimeType: "image/jpeg")

}, encodingCompletion: { (encodingResult) -> Void in
switch encodingResult {
case .Success(request: _, streamingFromDisk: _, streamFileURL: _):
finalResult = Result.Success(self)
callCompletion()
case .Failure(let errorType):
let error = errorType as NSError
finalResult = Result.failureForError(error, data: nil)
callCompletion()
}
}
)

最佳答案

在调查了近 4 个小时后,我发现 API 也需要文件名,这是我更改的行,一切正常。

multipartFormData.appendBodyPart(data: imageData, name: ParameterKey.Avatar, fileName: "avatar.jpg", mimeType: "image/jpeg")

关于ios - Alamofire multipartFormData 上传不发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33176280/

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