title: Converting file to Base64 URL safe encoding format in iOS
body: <p>I am supposed to convert a file in to <strong>Base64</strong> and add that String to a JSON which I am appending to a URL. The files that I am having are a <strong>.zip</strong> file and a text file with <em>.info</em> extension. The <em>.info</em> file is uploading correctly but with <strong>.zip</strong> file I am getting "<strong><em>Incorrect Padding</em></strong>" error as response from the server. </p>
  
  <p>Below is my work;</p>
  
  <pre><code>- (void)uploadingData: (NSString *)fileName {
  
      NSArray *directoryPathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [directoryPathsArray objectAtIndex:0];
  
      NSString *absoluteFilePath = [NSString stringWithFormat:@"%@/%@/%@", documentsDirectory, baseDirName, fileName];
  
      NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:absoluteFilePath];
      [inputStream open];
  
      uint8_t buffer[1024];
  
      int len;
  
      NSMutableString *total = [[NSMutableString alloc] init];
  
      while ([inputStream hasBytesAvailable]) {
          len = [inputStream read:buffer maxLength:sizeof(buffer)];
  
          if (len &gt; 0) {
               [total appendString: [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding]];
          }
      }
  
  
      NSData *plainData = [total dataUsingEncoding:NSUTF8StringEncoding];
      NSString *base64String = [plainData base64EncodedStringWithOptions:0];
  
  // Adding to JSON and upload goes here.
  }
  </code></pre>
  
  <p>Where I have done the mistake? </p>
  
  <p>Additionally, is there a way I can check the converted string is exactly according to Base64, before it append to JSON and upload to server?</p>
  
  <p>Thanks</p>