title: Storing data to google cloud storage using gae for java
body: <p>i am trying to store data from the app engine app to google cloud storage.</p>
  
  <p>if i do it locally code runs fine but i dont see any data being stored.</p>
  
  <p>if i upload the app to the app engine then i get a null pointer exception on running the code at:
  AppEngineFile writableFile = fileService.createNewGSFile(optionsBuilder.build());</p>
  
  <p>the complete code i m using is</p>
  
  <pre><code>        // Get the file service
          FileService fileService = FileServiceFactory.getFileService();
  
          /**
           * Set up properties of your new object
           * After finalizing objects, they are accessible
           * through Cloud Storage with the URL:
           * http://commondatastorage.googleapis.com/my_bucket/my_object
           */
          GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
            .setBucket("blood")
            .setKey("1234567")
            .setAcl("public-read")
            .setMimeType("text/html");//.setUserMetadata("date-created", "092011", "owner", "Jon");
  
  
          // Create your object
          AppEngineFile writableFile = fileService.createNewGSFile(optionsBuilder.build());
  
          // Open a channel for writing
          boolean lockForWrite = true; // Do you want to exclusively lock this object?
          FileWriteChannel writeChannel = fileService.openWriteChannel(writableFile, lockForWrite);
          // For this example, we write to the object using the PrintWriter
          PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
          out.println("The woods are lovely and deep.");
          out.println("But I have promises too keep.");
  
          // Close the object without finalizing.
          out.close();
  
          // Finalize the object
          writeChannel.closeFinally();
          System.out.println("Completed writing to google storage");
  </code></pre>