IOS 7将任务从文件上传到GRAILS

时间:2014-04-03 09:32:38

标签: ios grails nsurlsession nsurlsessionuploadtask

我尝试使用NSURLSession和NSURLSessionUploadTask将文件从IOS应用程序上传到GRAILS后端。

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];

请求成功点击服务器,但遗憾的是我不知道如何从请求中上传文件。我试过了:

request.getFile('gpsJsonFile.txt')

request.getFile('file')

但不适合我。有人知道uploadTaskWithRequest方法如何将文件放在请求中吗?

0 个答案:

没有答案