0
我想上傳一個PNG圖像和一些PARAMS我軌服務器和 我遵循http://nsscreencast.com/episodes/31-posting-multi-part-forms-with-afnetworkingAFNetworking不打成功和錯誤
這個例子,我的代碼片斷如下
代碼運行時,我看到進展從0到95..98%(它看起來並不是完成了)..它從來沒有擊中我的軌道控制器。它會凍結我的iOS應用程序......任何想法爲什麼它會凍結我的應用程序?我究竟做錯了什麼?謝謝,任何意見或意見,歡迎/讚賞。
NSData *imageData = UIImagePNGRepresentation(image);
NSDictionary *params = @{
@"latte[location]" : @"value1",
@"latte[submitted_by]" : @"value2",
@"latte[comments]" : @"value3"
};
NSURLRequest *putRequest = [[MApiClient sharedInstance] multipartFormRequestWithMethod:@"PUT"
path:@"somepath.json"
parameters:params
constructingBodyWithBlock:^(id formData) {
[formData appendPartWithFileData:imageData
name:@"latte[photo]"
fileName:@"latte.png"
mimeType:@"image/png"];
}];
AFHTTPRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:putRequest];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"%f", (totalBytesWritten/(float) totalBytesExpectedToWrite));
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (operation.response.statusCode == 200 || operation.response.statusCode == 201) {
NSLog(@"whats here, %@", responseObject);
} else {
NSLog(@"whats here, %@", responseObject);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"whats here, %@", error);
}];
[[MyApiClient sharedInstance] enqueueHTTPRequestOperation:operation];