0

Here i am Getting image path ,i am converted the path as nsdata ,but in server side receiving empty ...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //You can retrieve the actual UIImage
    _signupImgView.image = [info valueForKey:UIImagePickerControllerOriginalImage];
    //Or you can get the image url from AssetsLibrary
    NSURL *path = [info valueForKey:UIImagePickerControllerReferenceURL];
    imageSending=[UIImage imageWithData:[NSData dataWithContentsOfURL:path]];
      imgdata = UIImagePNGRepresentation(imageSending);//here i am converting as nsdata...
    [picker dismissViewControllerAnimated:YES completion:^{
    }];
}

This is my post code

-(void)signupScreen:(NSString *)firstName :(NSString *)emailID :(NSString *)phoneNumber :(NSString *)password :(NSData *)img
{
    NSString *strSignupScreenRequest=[NSString stringWithFormat:@"firstname=%@&email=%@&telephone=%@&password=%@&pic=%@""%@",firstName,emailID,phoneNumber,password,img];
    NSData *dataFetch=[strSignupScreenRequest dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
    NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:localRegister]];
    [self requestFunction:url :dataFetch:NO];

}

This is my post method assigned globally....

else
    {
        [request setURL:url];
        [request setHTTPMethod:@"POST"];

        NSString *conLength=[NSString stringWithFormat:@"%lu",(unsigned long)data.length];
        [request setValue:conLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-" forHTTPHeaderField:@"Content-Type"];

        [request setHTTPBody:data];
        NSLog(@"post method ===%@",request);
    }

i have seen most of the people say AFNETWORKING is good way in that many file is there i don't know how to achieve please any one guide me....

Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47
  • Whats the actual issue? Did you try with `AFNetworking`? If tried whats the error you're facing? Also, post the code of how you're uploading to it to your server. – Adil Soomro Sep 16 '15 at 10:50
  • Can you please put a breakpoint and check if your `imgdata ` has data and is not nil. Also, could you please share the code you are using to make server call and send this data. – Abhinav Sep 16 '15 at 10:52

2 Answers2

2

This is not the way to transmit data to server. You are converting everything in NSString and then probably sending it.

Here is how you should do it. This thread shows how to send image data along with other details. Read through all the answers.

Community
  • 1
  • 1
Abhinav
  • 37,684
  • 43
  • 191
  • 309
0
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

     [picker dismissViewControllerAnimated:YES completion:nil];
     SomeImageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

}

Image is in SomeImageView now.You can convert it to NSData

 NSData *imageData =UIImageJPEGRepresentation(image, 1.0);

and upload it using multipart/form-data If you need code for that, Goto this tutorial. Best I could suggest : http://nthn.me/posts/2012/objc-multipart-forms.html

Mujib Saiyyed
  • 158
  • 10