如何使用 ASIFormDataRequest 将图像上传到服务器?我试图上传一张图片,它在插入时没有显示任何错误。并在我的请求中完成了方法,我得到了成功的响应。所以问题是,当我得到我插入的数据时,我无法获得我插入的图像,但我也得到了图像路径。
这是我的代码
NSString *globalurl =[[NSUserDefaults standardUserDefaults]valueForKey:@"Global_Url"];
NSString *urlStr=[NSString stringWithFormat:@"%@/InsertUserInfo?User_Name=%@&User_Pwd=%@&User_FName=%@&User_LName=%@&User_Mail=%@&User_Phno=%@&User_Address=%@&User_Dob=%@&Ic_No=%@&User_Active=%@&User_Questions=%@&User_Ans=%@",globalurl,usernameTxtFld.text,pwdTxtFld.text,firstName.text,lastName.text,email.text,phonNO.text,address.text,dateOfbirth.text,nricNo.text,@"10001",@"",@""];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlStr]];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request addData:dataImage withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];
//check if passedData is nil
if (dataImage == nil)
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"title:iDnil" message:@"nil" delegate:nil cancelButtonTitle:@"fgff" otherButtonTitles:@"erer", nil];
[alert show];
}
[request startAsynchronous];
-(void)requestFinished:(ASIHTTPRequest *)request {
NSString *receivedString = [request responseString];
NSLog(@"received messge %@",receivedString);
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:receivedString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
NSLog(@"dict is %@",info);
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
}