我有一个 UItextView,我可以在其中放置图像并输入文本,一旦完成 TextView,我就会将该 textView 的内容上传到 Parse。
如果我只向 textView 添加 1 个图像,它可以让我将 UITextView 内容上传到 Parse,不会出现任何问题,但是当我添加超过 1 个图像时,我会收到错误“数据大于 10mb 等...”。
现在我想知道如何减小这个 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)
最佳答案
您应该调整图片大小以确保其尺寸较小以便上传。请参阅this answer
关于ios - 减少解析 PFFile、图像和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36675419/