0

I have a system using Parse that has a web front end and a iOS and Android client. Everything was working fine until we moved to HTTPS

Still everything works fine on Android and Web (Javascript) however I get the following message when I try to upload a file in iOS

JSON text did not start with array or object and option to allow fragments not set.

The code that is causing it is. It only fails if I include a picture in the upload (Search.sharedInstance.imageURL != nil)

// Send to Parse             
if PFUser.currentUser() != nil {
    sentReport["user"] = Search.sharedInstance.currentUser
}

sentReport["reportType"] = userSelectedReportType

Search.sharedInstance.reportText = reportNotesTextView.text
sentReport["reportDescription"] = Search.sharedInstance.reportText

if (reportLatCoords != nil && reportLngCoords != nil) {
    sentReport["reportPosition"] = PFGeoPoint(latitude: reportLatCoords!, longitude: reportLngCoords!)
}

sentReport["search"] = Search.sharedInstance.selectedPerson

let reportImageFile = PFFile(name: "\(Search.sharedInstance.timeStamp).jpg", data: reportImage!)

if reportPhoto.image != UIImage(named: "selectPhoto") {
    if Search.sharedInstance.imageURL != nil {
        sentReport["reportPicture"] = reportImageFile
        sentReport.setObject(Search.sharedInstance.imageURL!.absoluteString, forKey: "reportImageUri")
    }
}

sentReport["loggedAt"] = date

// Handle success & failure
sentReport.saveInBackgroundWithBlock { (success, error) -> Void in

    if success == true {
        self.dismissViewControllerAnimated(true, completion: { () -> Void in })
    } else {

        if Reachability.isConnectedToNetwork() == false {
            sentReport.pinInBackgroundWithBlock { (success, error) -> Void in
                if success {
                    Search.sharedInstance.syncReportItemsWithServer()
                }
            }
            self.displayAlert("No internet connection available", message: "But don't worry, your report will be sent automatically when you regain an internet connection.")
        }
    }
}    

The bit I am struggling is, that I read /parse fixes this a lot of the time however I have no control over the image upload. Also it works fine in the Android SDK?

My server address is : https://lowlands.lab-cloud.net/parse

Update

ReportImage

 var reportImage = UIImageJPEGRepresentation(self.reportPhoto.image!,
    1.0)

if reportImage!.length < 10000000 {
    reportImage = UIImageJPEGRepresentation(self.reportPhoto.image!, 0.75)
} else if (reportImage!.length >= 10000000) && (reportImage!.length <= 20000000) {
    reportImage = UIImageJPEGRepresentation(self.reportPhoto.image!, 0.50)
} else if (reportImage!.length > 20000000) {
    reportImage = UIImageJPEGRepresentation(self.reportPhoto.image!, 0.25)
}

1 Answer 1

2

The problem will be with your reportImage variable, unfortunately you didnt share it with us... this is how you store UIImages in PFFIle

let imageData = UIImagePNGRepresentation(image)
let imageFile = PFFile(name:"image.png", data:imageData)

var userPhoto = PFObject(className:"UserPhoto")
userPhoto["imageName"] = "My trip to Hawaii!"
userPhoto["imageFile"] = imageFile
userPhoto.saveInBackground()
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry what do you mean? this was working until I went to https
ok so it wont be probably in the Image storing... could you try adding slash or removing the last slash when you define your server in the Parse config so it will end with /parse or /parse/ or try /parse/1/
/1/ is the original parse hosted service ain't it? I will try though
I am able to login and do stuff, its just uploading the image that fails

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.