I have successfully implemented an asynchronous way to save data objects as detailed in the API. On a button press, the save object is called and successfully uploads the data (along with a file object as well). However once this is successfully submitted I would like to be able to submit another one. However the second time this is called, it always returns fault 400 Bad Request. I have checked and the file url is different for each submission.
Any help would be appreciated, thanks
the error received on submitting a second data object:
============ Uploading files with the ASYNC API ============
Server reported an error: FAULT = ‘400’ [HTTP 400] <bad request>
Note: The code below is called when a “Upload” button is pressed.
let imageData: NSData = UIImagePNGRepresentation(newImage)!
backendless.fileService.upload("issueImage/upload" + uniqueId + "file.txt", content: imageData,
response: { ( uploadedFile : BackendlessFile!) -> () in
//SUCESSFULL UPLOAD
print("File has been uploaded. File URL is - \(uploadedFile.fileURL)")
let formStore = self.backendless.persistenceService.of(Form().ofClass())
let form = Form()
form.latData = self.latData
form.longData = self.longData
form.dateTime = self.date
form.field1 = self.field1.text
form.field2 = self.field2.text
form.field3 = self.field3.text
// save object asynchronously
formStore.save(
form,
response: { (result: AnyObject!) -> Void in
let obj = result as! Form
//SUCCESS UPLOADING DATA
print("Contact has been saved: \(obj.objectId)")
let alert = UIAlertView(title: "Submitted", message: "Form submitted", delegate: self, cancelButtonTitle: "OK")
alert.show()
//Make textfields Nil when the submit is successful
self.field1.text = nil
self.field2.text = nil
self.field3.text = nil
},
error: { (fault: Fault!) -> Void in
//ERROR UPLOADING DATA
print("fServer reported an error: \(fault)")
let alert = UIAlertView(title: "ERROR", message: "Could not submit Form", delegate: self, cancelButtonTitle: "OK")
alert.show()
})
},
error: { ( fault : Fault!) -> () in
//ERROR UPLOADING IMAGE FILE
print("Server reported an error: \(fault)")
let alert = UIAlertView(title: "ERROR", message: "Could not submit form", delegate: self, cancelButtonTitle: "OK")
alert.show()
}