0
votes

On the server side is a PHP web service that accepts post parameters userid, authenticationKey, some title, some comments and a file

I am recording an audio on the iPhone and uploading to this service. The code works fine if I use NSURLSessionUploadTask and construct a multi part file upload request with DefaultSessionConfiguration

I want to however upload the file using Background Session configuration.

I could not find any sample code for background file upload (along with some parameters) in the post request. I am using Swift and iOS 8

Would appreciate your help.

Thanks. Sara

2

2 Answers

0
votes

You can either write the data to a file on disk and provide the upload body as a file URL or (IIRC) you can create an NSURLRequest object, set the bodyData property to an NSData blob, and use an NSURLDownload request. I'm not 100% certain that the latter approach works, though—you may have to provide the body as a body stream, which is kind of a pain in the backside.

0
votes

I have successfully uploaded a file with extra form data (parameters) in the background. This was done by creating the full body request manually and saving that blob of bytes as a file.

Then I could start an uploadTask that would upload that file even when the app went to the background.

After upload, I delete the file.