user5899631
user5899631

Reputation:

Reduce Parse PFFile, images and text

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)

Upvotes: 0

Views: 62

Answers (1)

Mo Nazemi
Mo Nazemi

Reputation: 2717

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

Upvotes: 0

Related Questions