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 {
NSLog(@"%@ %@", response, responseObject);
}
}];
[uploadTask resume];
クラッシュの結果は次のとおりです。
* キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了します。理由: '* -streamStatus は抽象クラスに対してのみ定義されています。定義 -[AFMultipartBodyStream streamStatus]!' *最初のスロー コール スタック: ( 0 CoreFoundation 0x019d91e4exceptionPreprocess + 180 1 libobjc.A.dylib 0x017588e5 objc_exception_throw + 44 2 CoreFoundation 0x019d8fbb +[NSException raise:format:] + 139 3 Foundation 0x01433b3b NSRequestConcreteImplementation + 218 4 Foundation 0x0143b746 -[NSStream(NSStream) streamStatus] + 48 5 readWritePlist 0x000333a1 -[AFMultipartBodyStream open] + 49 6 CoreFoundation 0x0199ac44 CFReadStreamOpen + 116 7 CFNetwork 0x026f395d _ZN30CoreReadStreamFromCFReadStream16_streamImpl_OpenEP13CFStreamErrorPh + 53 8 CFNetwork 0x027c5ae6 _ZThn60_N30CoreReadStreamFromCFReadStream16_streamImpl_OpenEP13CFStreamErrorPh + 34 9 CFNetwork 0x026d1112 _ZN14CoreStreamBase21_streamInterface_OpenEv + 72 10 CFNetwork 0x026f2c34_ZN17HTTPNetConnection19prepareTransmissionEP17HTTPNetStreamInfoP17__CoreWriteStream + 1614 11 CFNetwork 0x026f2063 _ZN17HTTPNetConnection19requestStateChangedEPvN13NetConnection5StateEP13CFStreamError + 415 12 CFNetwork 0x026f21fd _ZN13NetConnection18scheduleNewRequestEP13_CFNetRequestS1_h + 293 13 CFNetwork 0x026f1da4 _ZN13NetConnection7enqueueEPvh + 538 14 CFNetwork 0x026f1b26 _ZN17HTTPNetStreamInfo16_streamImpl_OpenEP13CFStreamErrorPh + 104 15 CFNetwork 0x02756846 _ZThn60_N17HTTPNetStreamInfo16_streamImpl_OpenEP13CFStreamErrorPh + 34 16 CFNetwork 0x026d1112 _ZN14CoreStreamBase21_streamInterface_OpenEv + 72 17 CFNetwork0x026f1315 _ZN12HTTPProtocol10openStreamEv + 267 18 CFNetwork 0x0276498c _ZN12HTTPProtocol26useNetConnectionForRequestEP13NetConnectionP15__CFHTTPMessageh + 1550 19 CFNetwork 0x026f05d8 _ZN24HTTPConnectionCacheEntry28dispatchConnectionToProtocolEP13NetConnectionP12HTTPProtocolP18HTTPRequestMessageh + 284 20 CFNetwork 0x026f03b9 _ZN24HTTPConnectionCacheEntry34notifyNextProtocolOfOpenConnectionEP13NetConnectionh + 349 21 CFNetwork 0x026ed71d _ZN24HTTPConnectionCacheEntry25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage + 637 22 CFNetwork 0x026ed0db _ZN19HTTPConnectionCache34_onqueue_enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage + 185 23 CFNetwork0x0276a897 ___ZN19HTTPConnectionCache25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage_block_invoke + 35 24 CoreFoundation 0x0197ac69 CFArrayApplyFunction + 57 25 CFNetwork 0x026e8441 _ZN19RunloopBlockContext7performEv + 155 26 CFNetwork 0x027ca3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20 27 CFNetwork 0x026e8257 _ZN17MultiplexerSource7performEv + 299 28 CFNetwork 0x026e806c _ZN17MultiplexerSource8_performEPv + 76 29 CoreFoundation 0x0196277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION___ZN19HTTPConnectionCache25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage_block_invoke + 35 24 CoreFoundation 0x0197ac69 CFArrayApplyFunction + 57 25 CFNetwork 0x026e8441 _ZN19RunloopBlockContext7performEv + 155 26 CFNetwork 0x027ca3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20 27 CFNetwork 0x026e8257 _ZN17MultiplexerSource7performEv + 299 28 CFNetwork 0x026e806c _ZN17MultiplexerSource8_performEPv + 76 29 CoreFoundation 0x0196277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION___ZN19HTTPConnectionCache25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage_block_invoke + 35 24 CoreFoundation 0x0197ac69 CFArrayApplyFunction + 57 25 CFNetwork 0x026e8441 _ZN19RunloopBlockContext7performEv + 155 26 CFNetwork 0x027ca3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20 27 CFNetwork 0x026e8257 _ZN17MultiplexerSource7performEv + 299 28 CFNetwork 0x026e806c _ZN17MultiplexerSource8_performEPv + 76 29 CoreFoundation 0x0196277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION0x026e8441 _ZN19RunloopBlockContext7performEv + 155 26 CFNetwork 0x027ca3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20 27 CFNetwork 0x026e8257 _ZN17MultiplexerSource7performEv + 299 28 CFNetwork 0x026e806c _ZN17MultiplexerSource8_performEPv + 76 29 CoreFoundation 0x0196277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION0x026e8441 _ZN19RunloopBlockContext7performEv + 155 26 CFNetwork 0x027ca3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20 27 CFNetwork 0x026e8257 _ZN17MultiplexerSource7performEv + 299 28 CFNetwork 0x026e806c _ZN17MultiplexerSource8_performEPv + 76 29 CoreFoundation 0x0196277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTIONCoreFoundation 0x0196277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTIONCoreFoundation 0x0196277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION+ 15 30 CoreFoundation 0x0196210b CFRunLoopDoSources0 + 235 31 CoreFoundation 0x0197f1ae __CFRunLoopRun + 910 32 CoreFoundation 0x0197e9d3 CFRunLoopRunSpecific + 467 33 CoreFoundation 0x0197e7eb CFRunLoopRunInMode + 123 34 Foundation 0x01353ece +[NSURLConnection(Loader) _resourceLoadLoop:] + 381 35 Foundation 0x013afa07 -[NSThread main] + 76 36 財団 0x013af966 __NSThread__main+ 1275 37 libsystem_pthread.dylib 0x0241d5fb _pthread_body + 144 38 libsystem_pthread.dylib 0x0241d485 _pthread_struct_init + 0 39 libsystem_pthread.dylib 0x02422cf2 thread_start + 34 ) libc++abi.dylib: タイプ NSException のキャッチされない例外で終了する
ここで私の間違いは何ですか..!?