我正在尝试使用AFNetwork上传一个NSData图像,但出现了问题,我无法找到我的错误
这是我的代码:
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"test.jpg"], 0.1);
NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"this is only a test post for \"app\".", @"app",
@"this POST for \"test\". ", @"test", nil];
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://url/upload.php" parameters:postParm constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg" ];
} error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSProgress *progress = nil;
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else …Run Code Online (Sandbox Code Playgroud) nsdata afnetworking afnetworking-2 nsurlsession nsurlsessionuploadtask