title: Cordova : writing in a file
body: <p>There is something i've been stuck for quite some time, despite me searching on numerous forums. I'm sorry if my english is not perfect, I hope I'm clear enough for you to be able to understand me and help me get through this.</p>
  
  <p>I'm trying to learn some mobile development with Cordova.
  I want to create an application instagram-like, in which memories will be stored. The application uses two pages :
  - a page displaying all stored memories ;
  - a page adding a memory. Memories are stored in a local json file.</p>
  
  <p>Here is my code (for now) :
  <em>note : the code has been translated for better comprehension. I hope I didn"t make any translation error, unrelated to the topic at hand</em></p>
  
  <p><strong>addMemory.html (view to add a memory)</strong></p>
  
  <pre><code>&lt;form role="form" class="col-xs-12"&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="title"&gt;Title :&lt;/label&gt;
          &lt;input type="text" id="title" class="form-control" ng-model="souvenir.title" placeholder="Add a memory title" /&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="image"&gt;Image :&lt;/label&gt;
          &lt;button id="image" class="form-control btn btn-default"&gt;Add...&lt;/button&gt;
      &lt;/div&gt;
      &lt;button class="btn btn-default" ng-click="createMemory()"&gt;Create&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>addMemoryController.js</strong> <em>(add a memory. For now, a memory is a static json stored in a local file. Dynamic control will be added later on)</em></p>
  
  <pre><code>app.controller("addMemoryController", function ($scope, $location) {
    //Array of all stored memories
    $scope.memoriesList = [];
  
    //New memory to add (for now static)
    $scope.memory = {
        image: "image/moutain.png",
        title:""
    }
  
    //The function pushes the new memory into the list then save the array
    $scope.createMemory = function () {
        $scope.memoriesList.push($scope.memory);
        $scope.saveArray();
    }
  
    //The function save the array into the local file
    $scope.saveArray = function () {
        window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
        var requestedBytes = 1024*1024*10; // 10MB
        navigator.webkitPersistentStorage.requestQuota (
            requestedBytes,
            function (grantedBytes) {
                window.requestFileSystem(PERSISTENT, grantedBytes, $scope.fileSystemReceived, $scope.errorHandler('requestFileSystem'));
            },
            $scope.errorHandler
        );
        $location.path("/");
    }
  
    //Function called when the fileSystem is received
    $scope.fileSystemReceived = function (fileSystem) {
        fileSystem.root.getFile("memories.json", { create: true, exclusive: false }, $scope.fileEntryReceived, $scope.errorHandler('getFile'));
    }
  
    //Function called when the fileEntry is received
    $scope.fileEntryReceived = function (fileEntry) {
        fileEntry.createWriter($scope.fileWriterReceived, $scope.errorHandler('createWriter'));
    }
  
    //Function called when the fileWriter is received
    $scope.fileWriterReceived = function (fileWriter) {
        fileWriter.onwrite = function (evt) {
            console.log("write success");
        };
        var memoriesListText = angular.toJson($scope.memoriesList);
        fileWriter.write(memoriesListText);
  
    }
  
    //Error managment
    $scope.errorHandler = function (errorMessage) {
        return function () { console.log(errorMessage); };
    }
  });
  </code></pre>
  
  <p>When I launch my application, I get an error with the "write" function :
  <em>TypeMismatchError: The type of an object was incompatible with the expected type of the parameter associated to the object.</em></p>
  
  <p>I tried to write a simple text content without any difference :</p>
  
  <pre><code>fileWriter.write("some text");
  </code></pre>
  
  <p>I even tried to create a ".txt" file, logically without any difference.     </p>
  
  <p>What am I supposed to give as parameter if not a text ? I can't file a doc describing this function type signature.</p>