Click here to Skip to main content
15,745,750 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi All,

I want to send an image from iOS to wcf service to save it in my Sql server DB.

so I did the following, but I cannot save the Data in the DB.

    UIImage *myImage = imageView.image;
    NSString *imgBase = [self encodeToBase64String:myImage]; // encoding the image
          NSString *str= @"http://server/ServiceAlizonne.svc/json/";
        str=[str stringByAppendingFormat:@"InsertNewFood/%@" , imgBase];
        str=[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURL *WcfSeviceURL = [NSURL URLWithString:str];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:WcfSeviceURL];
        [request setHTTPMethod:@"POST"];
        NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

so the issue here is that I get the imgBase value with some characters (/ \ + ..) that doesn't called the web service .

can you please help me on this please,

1 solution

Instead of sending it like this, try sending a multipart request.

Send request from iOS like this[^]

Handle it on server side like this[^] (This is a c# code to give you an example).

I have used it and it works perfect for both when we have some arguments along with image data or just simple some image data.

Hope it helps!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900