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?