gpt4 book ai didi

ios - 上传图片时出错

转载 作者:行者123 更新时间:2023-11-30 11:42:50 25 4
gpt4 key购买 nike

无法将图像上传到服务器...

这是代码:

let chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage
let data = UIImageJPEGRepresentation(chosenImage, 1)

Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(data, withName: "avatar_image")
},
to: url,
method: .put,
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
})

如果将 data 更改为 let data = Bundle.main.url(forResource: "flag", withExtension: "png")! 则会将此图像上传到服务器。

为什么无法从我的照片库上传图片?

最佳答案

您可以尝试原创而不是编辑

let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage

关于ios - 上传图片时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49157888/

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