title: How to write UIImage to NSOutputStream with complete data
body: <p>How to send UIImage to NSOutputStream with complete data. 
  I have try this code but output not write complete image. How to send to output with complete data of image.</p>
  
  <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker
          didFinishPickingImage:(UIImage *)image
                    editingInfo:(NSDictionary *)editingInfo
  {
    NSData *imgData = UIImageJPEGRepresentation(image, 0.2);
  
      NSMutableData *completeData = [[NSMutableData alloc] initWithBytes:[stringData bytes] length:[stringData length]];
      [completeData appendData:imgData];
  
      NSInteger bytesWritten = 0;
      while ( imgData.length &gt; bytesWritten )
      {
        while ( ! self.outputStream.hasSpaceAvailable )
             [NSThread sleepForTimeInterval:0.05];
  
          //sending NSData over to server
          NSInteger writeResult = [self.outputStream write:[imgData bytes]+bytesWritten maxLength:[imgData length]-bytesWritten];
          if ( writeResult == -1 )
              NSLog(@"error code here");
         else
              bytesWritten += writeResult;
      }
  }
  </code></pre>