title: How to minimize the length of the base64 string from nsdata of image?
body: <p>I convert an image to NSData and NSData to base64string using</p>
  
  <pre><code>NSData *imagedata = UIImageJPEGRepresentation(imageView.image, 0.1f);
  NSString *c = [NSString base64StringFromData:imagedata];
  </code></pre>
  
  <p>the fn for stringconversion</p>
  
  <pre><code>+ (NSString*)base64forData:(NSData*)theData {
  
      const uint8_t* input = (const uint8_t*)[theData bytes];
      NSInteger length = [theData length];
  
      static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  
      NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
      uint8_t* output = (uint8_t*)data.mutableBytes;
  
      NSInteger i;
      for (i=0; i &lt; length; i += 3) {
          NSInteger value = 0;
          NSInteger j;
          for (j = i; j &lt; (i + 3); j++) {
              value &lt;&lt;= 8;
  
              if (j &lt; length) {
              value |= (0xFF &amp; input[j]);
             }
          }
  
          NSInteger theIndex = (i / 3) * 4;
          output[theIndex + 0] =                    table[(value &gt;&gt; 18) &amp; 0x3F];
          output[theIndex + 1] =                    table[(value &gt;&gt; 12) &amp; 0x3F];
          output[theIndex + 2] = (i + 1) &lt; length ? table[(value &gt;&gt; 6)  &amp; 0x3F] : '=';
          output[theIndex + 3] = (i + 2) &lt; length ? table[(value &gt;&gt; 0)  &amp; 0x3F] : '=';
      }
  
      return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
  }
  </code></pre>
  
  <p>but the resulted base64string is too long, its length is above 300000.
  ie, </p>
  
  <pre><code>int len = c.length;
  </code></pre>
  
  <p>value of len is above 300000.</p>
  
  <p>the image is of 3 to 4 mb
  infact I compress the image to 0.1f</p>
  
  <pre><code> NSData *imagedata = UIImageJPEGRepresentation(iivv.image, 0.1f);
  </code></pre>
  
  <p>how to minimize the length, is there any other code for base64conversion from NSData?</p>