0

I have a UItextView which I place images and type text into, and once I have finished with the TextView I then upload the contents of that textView to Parse.

If I only add 1 image to the textView it lets me upload the UITextView contents to Parse without any problems, but when I add more than 1 Image I get the error "data is larger than 10mb etc...".

Now I am wondering how I can reduce the size of this PFFile?

Or is their a way to reduce the size of the images before or after adding the to the textView? possibly extract the from th etextView and reduce there size before uploading to Parse?

This is my code:

Here is where the text & images from the textView are stored:

var recievedText = NSAttributedString()

And here Is how I upload it to 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
   })

Best regards.

How I add the images

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)

1 Answers1

0

You should to resize the picture to make sure it is small size for upload. See this answer

Community
  • 1
  • 1
Mo Nazemi
  • 2,618
  • 2
  • 16
  • 23
  • But how would I get the images out of the UITextView before uploading to parse? when I upload the file, I upload the text which has the images inside –  Apr 18 '16 at 16:01
  • 1
    Don't you have to resize them before adding them to the textview ?? – Mo Nazemi Apr 18 '16 at 16:58
  • Figured it out thanks to you! thank you very much for the help! –  Apr 18 '16 at 17:55