AFNetworking 3.0でサーバーにイメージをアップロードしようとしています。画像アップロードでエラー:イメージAFNetworking 3.0でアップロードする
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[[manager POST:setUrl parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData)
{
//Current date with image name
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss a"];
[formData appendPartWithFileData:image name:namePara fileName:[NSString stringWithFormat:@"img_%@",[dateFormatter stringFromDate:[NSDate date]]] mimeType:@"image/png"];
}progress:nil
success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject)
{
NSLog(@"%@",responseObject);
[GMDCircleLoader hideFromView:self.view animated:YES];
NSMutableDictionary *dir = [[NSMutableDictionary alloc]initWithDictionary:responseObject];
if([dir valueForKey:@"error"])
{
UIAlertController *alert = [[singletone sharedManager]showAlert:NSLocalizedString(@"SIGNIN", nil) :[NSString stringWithFormat: @"%@",[dir valueForKey:@"error"]] ];
[self.parentViewController presentViewController:alert animated:YES completion:nil];
}
else
{
//Successfull
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"REGISTRATION", nil) message:[dir valueForKey:@"success"] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * action)
{
[self.navigationController popViewControllerAnimated:YES];
}];
[alertController addAction:ok];
[self presentViewController:alertController animated:YES completion:nil];
}
NSLog(@"response object : %@",responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"failure : %@",error.localizedDescription);
}]resume];
それはエラーで成功ブロックになります:
は、ここに私のコードです。
私はまた、私のAPIレスポンスをチェックするためにPostmanから試しましたが、Postmanからうまくいっています。このコードの問題は何ですか?
ファイルをbase64またはシンプルファイルとして受け入れる – gurmandeep
レスポンスを表示しますか? –
はい。それはいいよ – gurmandeep