title: Pulling a base64 encoded string from http request in php
body: <p><strong>Background</strong></p>
  
  <p>I wrote a small test to make sure I could pull the data from a POST request made from my mobile application. It works fine,</p>
  
  <pre><code>$rawJsonObj = file_get_contents('php://input');
  $json = json_decode( $rawJsonObj, true );
  $decodedData = base64_decode($json['data']);
  file_put_contents('student-data/'.$json['username'].'.txt', $decodedData);
  </code></pre>
  
  <p>Then in my <code>Slim Framework</code> app I try the same logic and the actual data that I use to create the file with is null. But I can still access the username and password that are sent in the request. </p>
  
  <pre><code>$app-&gt;post('/api/v1/endpoint', function ($request, $response, $args) {
     $rawJsonObj = $request-&gt;getParams();
     $json = json_decode( $rawJsonObj, true );
     $decodedData = base64_decode($json['data']);
     file_put_contents('test.txt', $decodedData);
  return $response; 
  }
  </code></pre>
  
  <p>The username and password are showing in the request and I can see them when I write the data in the request to a file. </p>
  
  <pre><code> $data = $request-&gt;getParams();
   file_put_contents('2.txt', $data);
  </code></pre>
  
  <p>Data that is wrote to file,</p>
  
  <pre><code>","username":"myuname","password":"myPword"}
  </code></pre>
  
  <p>But the base64encoded string is missing, </p>
  
  <p><strong>Example</strong></p>
  
  <p>In Swift I am creating the dict like this, then POST it as json,</p>
  
  <pre><code>let dict: [String: Any] = [
      "username": named,
      "password": password,
      "data": data.base64EncodedString()
  ]
  
  if let json = try? JSONSerialization.data(withJSONObject: dict, options: []) {
      request.httpBody = json
  }
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>How do I access the actual <code>"data": data.base64EncodedString()</code> from the request body in <code>Slim Framework 3</code>?</p>
  
  <p>I assume this has to do with the way <code>$rawJsonObj = file_get_contents('php://input');</code> actually handles the data compared to Slim?</p>