我正在尝试像这样上传文件:
NSMutableDictionary * lParameters = [NSMutableDictionary dictionary];
[lParameters setObject:@"temp.jpg" forKey:@"file"];
NSMutableURLRequest *request = [self multipartFormRequestWithMethod:@"POST" path:@"uploads/add.json" parameters:lParameters constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
{
NSData * data = [NSData dataWithContentsOfFile:filePath];
[formData appendPartWithFileData:data name:@"temp.jpg" fileName:@"temp.jpg" mimeType:@"image/jpeg"];
}];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
....
我的上传 json 看起来像这样:
http://base/url/uploads/add.json
并且只有一个参数“文件”。服务器返回错误:“未指定强制参数:文件”。我应该如何设置参数。为什么不起作用:
NSMutableDictionary * lParameters = [NSMutableDictionary dictionary];
[lParameters setObject:@"temp.jpg" forKey:@"file"];
请帮忙。