title: Large Base64 uploads in iOS
body: <p><strong>Description:</strong>
  I need to send a base 64 encoded string in a HTTP POST parameter that represents a file to be uploaded.</p>
  
  <p><strong>Current method:</strong> I'm using a ASIFormDataRequest and encoding my file into a base64 string like so:</p>
  
  <pre><code>NSData *data = [[NSFileManager defaultManager] contentsAtPath:@"my path here"];
  NSString *base64Data = [data encodeBase64ForData];
  </code></pre>
  
  <p>However when uploading large files the App runs out of memory and dies a horrid death!</p>
  
  <p><strong>Proposed solution:</strong> Does anybody now how I would go about, say, reading the file from disk, converting it to base64 strings in chunks and attaching the converted base64 string to a parameter in the HTTP request?</p>
  
  <p>Effectively any way that avoids reading the whole file into memory.</p>
  
  <p>Any input would be greatly appreciated!</p>
  
  <p>My http request code in full:</p>
  
  <pre><code>NSURL *url = [NSURL URLWithString:requestProgressURLString];
  NSData *data = [[NSFileManager defaultManager] contentsAtPath:evidence.uri];
  NSString *base64Data = [data encodeBase64ForData];
  NSURL *fileURL = [[NSURL alloc] initWithString:evidence.uri];
  
  request = [ASIFormDataRequest requestWithURL:url];
  
  request.shouldAttemptPersistentConnection = false;
  [request setShowAccurateProgress:YES];
  
  [request setPostValue:accessToken forKey:@"AccessToken"];
  [request setPostValue:[[fileURL path] lastPathComponent] forKey:@"Filename"];
  [request setPostValue:evidence.name forKey:@"Title"];
  [request setPostValue:base64Data forKey:@"FileData"]; //wants string value (base64 encoded)          
  [request addRequestHeader:@"Content-Type" value:@"application/x-www-form-urlencoded"];
  [request setTimeOutSeconds:60];
  [request setUploadProgressDelegate:self];
  [request setDownloadProgressDelegate:self];
  [request setDelegate:self];
  [request setDidFinishSelector:@selector(requestDone:)];
  [request setDidFailSelector:@selector(requestWentWrong:)];
  </code></pre>