0

I'm trying to upload a file from an IOS app to a GRAILS backend using NSURLSession and NSURLSessionUploadTask.

NSURL *uploadURL = [NSURL URLWithString:@"http://192.168.1.71:8080/copesmart/mobileInstance/uploadOneFile"];
NSURLRequest *request = [NSURLRequest requestWithURL: uploadURL];

//get the documents directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//make a file name to write the data to using the documents directory:
NSString *fileName = [NSString stringWithFormat:@"%@/gpsJsonFile.txt",
                      documentsDirectory];    

self.uploadTask = [self.session uploadTaskWithRequest:request fromFile:[NSURL URLWithString:[NSString stringWithFormat:@"file://%@", fileName]]];
[self.uploadTask resume];

The request hits the server successfully but unfortunately I don't know how to get the file uploaded from the request. I've tried:

request.getFile('gpsJsonFile.txt')

and

request.getFile('file')

but neither work for me. Does anybody know how the uploadTaskWithRequest method places the file in the request?

  • 1
    `*fileName` in the client side is what is required to get the file from request in server side. Try to log the actual value of `*fileName` in client and see if that value can be used as `request.getFile(fileName)` – dmahapatro Apr 03 '14 at 13:15
  • I'm having the same issue and its very frustrating. Apple has no documentation as to how the file upload request is generated and sent. For some reason requests from the app using this method can't be captured with Pony debugger or Rails logs. Were you able to find a solution? – KyleStew May 27 '14 at 08:05

0 Answers0