title: Python REST decoding the results of FileReader::readAsDataURL
body: <p>I am using Python / Django to process a REST request - one of the elements in the REST is the Data URI of a file to upload. It looks like everything is fine (js captures the file and builds the json correctly), but when I decode the file on the server and write the binary to disk it is different.</p>
  
  <p>I am new to python/django from a .NET and Java background - any help is more than appreciated.  Thank you</p>
  
  <p>HTML input control</p>
  
  <pre><code>&lt;input type="file" class="col-lg-6" style="padding-left: 0px" onchange="angular.element(this).scope().attachment = this.files[0]; angular.element(this).scope().$digest();"/&gt;
  </code></pre>
  
  <p>Add Image from my angular JS controller</p>
  
  <pre><code>$scope.addImage = function () {
      var attachment = $scope.attachment
      fr = new FileReader();
      fr.onload = function () {
          $scope.public_file = $scope.public_files.concat({filename: attachment.name, data: fr.result})
          $scope.$digest()
      };
      fr.readAsDataURL(attachment);
  }
  </code></pre>
  
  <p>Parsing on the server</p>
  
  <pre><code>def getData(uri):
      head, data = uri.split(',')
  
      decoded =data.decode('base64','strict');
      # decoded base64.b64decode(data)
      return decoded
  
  
    def create(self, request):
          data = getData(request['public_files'])
  
          with open(file_path, 'w+') as f:
              f.write(data)
  
          return super(UpdatingIdeasViewSet, self).create(request)
  </code></pre>
  
  <hr>
  
  <p>Comparing console.log(fr.result) on the client with request['public_files'] on the server yields the same string.  It must be a base64 decoding issue</p>