gpt4 book ai didi

json - 上传JPG图片解析服务器失败

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

我正在尝试上传图像文件到解析服务器。我可以正确上传 png 文件,但如果我选择 jpg 文件,则会收到如下错误

Creating an image format with an unknown type is an error Optional(Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set."

我正在使用这些代码上传图像;

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let imageUrl = info[UIImagePickerControllerReferenceURL] as! NSURL
let imageExt = imageUrl.pathExtension
var type = 1
if imageExt == "PNG" {
type = 0
}else if imageExt == "JPG" {
type = 1
}
profilePicture.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: false, completion: nil)
self.uploadImageToParse(image: profilePicture.image!,imageType:type)
}

func uploadImageToParse(image:UIImage,imageType:Int) {
let query = PFQuery(className: "cls_kullanicilar")
query.getObjectInBackground(withId: uObjectId) { (object, error) in
if error == nil {
if let object = object {
if imageType == 0 {
let fname = String(self.randomString(length: 12)+".png")
let imgData = UIImagePNGRepresentation(image)
let parseFile = PFFile(name: fname, data: imgData!)
object["profilePhoto"] = parseFile
//object["profil_foto"] = fname
object.saveInBackground(block: { (result, error) in
if error != nil {
print(error)
}
})
}else if imageType == 1 {
let fname = String(self.randomString(length: 12)+".jpg")
let imgData = UIImageJPEGRepresentation(image, 1.0)
let parseFile = PFFile(name: fname, data: imgData!)
object["profilePhoto"] = parseFile
//object["profil_foto"] = fname
object.saveInBackground(block: { (result, error) in
if error != nil {
print(error)
}
})
}
}
}else{
print("HATA")
}
}
}

我该如何处理这个问题?谢谢大家。

最佳答案

我找到了解决我的问题的方法。

我增加了 Nginx 上传大小。我的错。有时我无法思考所有事情。

关于json - 上传JPG图片解析服务器失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41534466/

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