【问题标题】:Reduce Parse PFFile, images and text减少 Parse PFFile、图像和文本
【发布时间】:2016-04-17 10:35:59
【问题描述】:

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

如果我只向 textView 添加 1 张图片,它可以让我将 UITextView 内容上传到 Parse 没有任何问题,但是当我添加超过 1 张图片时,我收到错误“数据大于 10mb 等...”。

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

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

这是我的代码:

这里是 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)

【问题讨论】:

    标签: ios swift parse-platform uiimage uitextview


    【解决方案1】:

    您应该调整图片的大小以确保它是小尺寸以便上传。见this answer

    【讨论】:

    • 但是在上传解析之前如何从 UITextView 中获取图像?当我上传文件时,我上传了里面有图片的文本
    • 在将它们添加到 textview 之前您不必调整它们的大小吗??
    • 感谢您!非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    相关资源
    最近更新 更多