title: Base 64 encoding random behaviour UIImage
body: <p>I am sending an image to the server by converting the NSData object into an NSString object using Base64 scheme by using....</p>
  
  <pre><code> NSData *imgData=UIImagePNGRepresentation([objCP userImage]);
   NSString *encodedString=[Base64Coder encodeData:imgData];
  </code></pre>
  
  <p>I am observing a random behavior....sometimes I get "==" in the encoded string at the end of the string and image does not uploaded.There may be some other characters also in between the string.If I do not get these characters at the end...image gets uploaded.
  To overcome this...I also used this method to convert these characters into valid(assumed to be accepted)::</p>
  
  <pre><code>-(NSString *)urlEncodedVersion:(NSString *)strString
  { 
      NSMutableString *strTemp = [[NSMutableString alloc] initWithFormat:@"%@",strString] ;
      NSArray *escapeChars = [NSArray arrayWithObjects:@";",@"?",@":",@"@", @"&amp;",@"=",@"+",@"$",@",", @"[",@"]",@"#",@"!",@"’",@"(", @")",@"*",@" ",nil];
  
      NSArray *replaceChars = [NSArray arrayWithObjects: @"%3B",@"%3F",@"%3A",
                               @"%40",@"%26",@"%3D", @"%2B",@"%24",@"%2C",@"%5B",@"%5D", @"%23",@"%21",@"%27", @"%28",@"%29",@"%2A",@"%20",nil];
  
      //NSMutableString *tempStr = [[self mutableCopy] autorelease]; 
      for(int i = 0; i &lt; [escapeChars count]; i++)
      {
          [strTemp replaceOccurrencesOfString:[escapeChars objectAtIndex:i] withString:[replaceChars objectAtIndex:i] options:NSLiteralSearch range:NSMakeRange(0,[strTemp length])];
      } 
      return strTemp;
  }
  </code></pre>
  
  <p>but it is also not serving.</p>
  
  <p><strong>This is my whole post body::</strong></p>
  
  <pre><code>-(void)uploadProfileInfo:(CreateProfile *)objCP
  {
  
      NSData *imgData=UIImagePNGRepresentation([objCP userImage]);
      NSString *encodedString=[Base64Coder encodeData:imgData];
  
      NSString *refinedString=[self urlEncodedVersion:encodedString];
  
      NSString *soapMessage = [NSString stringWithFormat:
  
                               @"&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n"
                               "&lt;soapenv:Envelope \n"
                               "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" \n"
                               "xmlns:tem=\"http://tempuri.org/\" \n"
                               "xmlns:wcf=\"http://schemas.datacontract.org/2004/07/NextToMe_BusinessEntity\"&gt; \n"
                               "&lt;soapenv:Header/&gt;\n"
                               "&lt;soapenv:Body&gt;\n"
                               "&lt;tem:CreateProfile&gt;\n"
  
                               "&lt;tem:objUser&gt;\n"
  
                               "&lt;wcf:Email&gt;%@&lt;/wcf:Email&gt;\n"
  
                               "&lt;wcf:Mode&gt;%@&lt;/wcf:Mode&gt; \n"
  
                               "&lt;wcf:Name&gt;%@&lt;/wcf:Name&gt;\n"
  
                               "&lt;wcf:ProfileImage&gt;%@&lt;/wcf:ProfileImage&gt;\n"
  
                               "&lt;wcf:RequestDateTime&gt;%@&lt;/wcf:RequestDateTime&gt;\n"
  
                               "&lt;wcf:Status&gt;%@&lt;/wcf:Status&gt;\n"
  
                               "&lt;wcf:StatusSpecified&gt;%@&lt;/wcf:StatusSpecified&gt;\n"
  
                               "&lt;wcf:UDID&gt;%@&lt;/wcf:UDID&gt;\n"
  
                               "&lt;/tem:objUser&gt;\n"
  
                               "&lt;/tem:CreateProfile&gt;\n"
  
                               "&lt;/soapenv:Body&gt;\n"
  
                               "&lt;/soapenv:Envelope&gt;\n",[objCP email],[objCP mode],[objCP name],encodedString,@"",[objCP status],[objCP statusSpecified],[objCP UDID]];
  
  
  
  
  
      NSURL *url = [NSURL URLWithString:kBaseURL];               
      NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];             
      NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];          
      [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];       
      [theRequest addValue: @"http://tempuri.org/XXXX/CreateProfile" forHTTPHeaderField:@"Soapaction"];
      [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
      [theRequest setHTTPMethod:@"POST"];     
      [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
      NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
  
      if( theConnection )
      {
          webData = [[NSMutableData data] retain];
      }
      else
      {
          NSLog(@"The Connection is NULL");
      }
  
  }
  </code></pre>