Saving Data Objects 1st time successful, 2nd time Fault 400 Bad Request IOS SWIFT

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()
 
 }

Hi joey!

Could you provide example of your code and full error message?

Sure, will update soon with code and error message
Edit: problem has been updated with replication code

I have isolated the problem. When I just use synchronous data object upload, everything works as expected. I have also tried synchronous object upload with asynchronous file upload and it breaks. I am having trouble implementing synchronous file upload, the API example does not work, i get an error with “Types.try” and it will not compile so I have no way of testing if upload will work with two synchronous methods.

I think I have traced the problem with Asynchronous file upload. However I have now ran into the problem of implementing Synchronous file upload. The API example does not work.

Also the example as found here: https://backendless.com/feature-31-uploading-files-to-server-with-the-file-upload-api/
Does not work either. It throws an xCode error with Types.try

Hi Joey,

The sample F31UploadingFiles used the ‘upload’ methods without ‘overwrite’ parameter, i.e. ‘overwrite’ == false (by default), and you will get
Server reported an error: FAULT = ‘400’ [HTTP 400] <bad request>
for the second (and next) file upload with the same path/name (because file is already exist)

We’ve fixed this issue (added ‘overwrite’ parameter), you could try this sample again. We’ll fix the doc asap.

Regards,
Slava

Thank you for fixing the issue, all is working as expected now!

Sorry to say, do you think is it the right way to let developer know what has gone wrong?

I spent my 2 hours thinking and changing codes and feeling like there is something wrong with my params!!
Kindly correct it with right description saying that the file already exists instead of saying request is bad!!