Reduce Parse PFFile、图像和文本

Reduce Parse PFFile, images and text

我有一个 UItextView,我可以在其中放置图像并键入文本,完成 TextView 后,我会将该 textView 的内容上传到 Parse。

如果我只向 textView 添加 1 张图片,它可以让我毫无问题地将 UITextView 内容上传到 Parse,但是当我添加多于 1 张图片时,我会收到错误 "data is larger than 10mb etc..."。

现在我想知道如何减小这个 PFFile 的大小?

或者他们是否有一种方法可以在将图像添加到 textView 之前或之后减小图像的大小?可能从 etextView 中提取并在上传到 Parse 之前减小尺寸?

这是我的代码:

这里是存储 textView 中的文本和图像的地方:

var recievedText = NSAttributedString()

这是我将其上传到 Parse 的方式:

let post = PFObject(className: "Posts")
    let uuid = NSUUID().UUIDString
    post["username"] = PFUser.currentUser()!.username!
    post["titlePost"] = recievedTitle
    let data: NSData = NSKeyedArchiver.archivedDataWithRootObject(recievedText)
    post["textPost"] = PFFile(name:"text.txt", data:data)
    post["uuid"] = "\(PFUser.currentUser()!.username!) \(uuid)"
    if PFUser.currentUser()?.valueForKey("profilePicture") != nil {
        post["profilePicture"] = PFUser.currentUser()!.valueForKey("profilePicture") as! PFFile
    }

    post.saveInBackgroundWithBlock ({(success:Bool, error:NSError?) -> Void in
   })

此致。

我如何添加图片

image1.image = images[1].imageWithBorder(40)
    let oldWidth1 = image1.image!.size.width;
    let scaleFactor1 = oldWidth1 / (blogText.frame.size.width - 10 )
    image1.image = UIImage(CGImage: image1.image!.CGImage!, scale: scaleFactor1, orientation: .Up)
    let attString1 = NSAttributedString(attachment: image1)
    blogText.textStorage.insertAttributedString(attString1, atIndex: blogText.selectedRange.location)

您应该调整图片大小以确保它是适合上传的小尺寸。参见