CtrlX
CtrlX

Reputation: 7015

Google Appengine & cloud storage : The AppIdentity service threw an unexpected error

I'm trying to setup a Google Cloud Storage file upload by following the sample from google with the GcsExampleServlet.java . I've complete all the step but when I deploy the project to aggengine and I try to upload a simple text in GCS , it fail with this log :

com.google.appengine.tools.cloudstorage.NonRetriableException: com.google.appengine.tools.cloudstorage.NonRetriableException: com.google.appengine.api.appidentity.AppIdentityServiceFailureException: 
The AppIdentity service threw an unexpected error. Details: 
at com.google.appengine.tools.cloudstorage.RetryHelper.doRetry(RetryHelper.java:120)
at com.google.appengine.tools.cloudstorage.RetryHelper.runWithRetries(RetryHelper.java:166)
at com.google.appengine.tools.cloudstorage.RetryHelper.runWithRetries(RetryHelper.java:156)
at com.google.appengine.tools.cloudstorage.GcsServiceImpl.createOrReplace(GcsServiceImpl.java:70)
at com.appart.storage.server.GcsExampleServlet.doPost(GcsExampleServlet.java:88)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
(...)

Still, there is nothing complicate in the code... In web.xml I've configured the servlet :

<servlet>
  <servlet-name>GcsExample</servlet-name>
    <servlet-class>
      com.example.server.GcsExampleServlet
    </servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>GcsExample</servlet-name>
  <url-pattern>/gcs/*</url-pattern>
</servlet-mapping>

Here is the servlet GcsExampleServlet.java ( exactly the same as in google sample ) :

@SuppressWarnings("serial")
public class GcsExampleServlet extends HttpServlet {

  private final GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()
      .initialRetryDelayMillis(10)
      .retryMaxAttempts(10)
      .totalRetryPeriodMillis(15000)
      .build());     
  //...
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException 
  {
    GcsOutputChannel outputChannel =
    gcsService.createOrReplace(getFileName(req), GcsFileOptions.getDefaultInstance());
    copy(req.getInputStream(), Channels.newOutputStream(outputChannel));
  }

  private void copy(InputStream input, OutputStream output) throws IOException {
    try {
      byte[] buffer = new byte[BUFFER_SIZE];
      int bytesRead = input.read(buffer);
      while (bytesRead != -1) {
        output.write(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
      }
    } finally {
      input.close();
      output.close();
    }
  }
}

Here is my upload.html file :

<form action="/upload.html" enctype="text/plain" method="get" name="putFile" id="putFile">
   <div>
        Bucket: <input type="text" name="bucket" />
        File Name: <input type="text" name="fileName" />
        <br /> File Contents: <br />
        <textarea name="content" id="content" rows="3" cols="60"></textarea>
        <br />
        <input type="submit" onclick='uploadFile(this)' value="Upload Content" />
   </div>
</form>
<script>

  function uploadFile() {
    var bucket = document.forms["putFile"]["bucket"].value;
    var filename = document.forms["putFile"]["fileName"].value;
    if (bucket == null || bucket == "" || filename == null || filename == "") {
      alert("Both Bucket and FileName are required");
      return false;
    } else {
      var postData = document.forms["putFile"]["content"].value;
      document.getElementById("content").value = null;

      var request = new XMLHttpRequest();
      request.open("POST", "/gcs/" + bucket + "/" + filename, false);
      request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
      request.send(postData);
    }
  }
</script>

I've enabled Billing, created a bucket but the AppIdentity error still appear. I've no Oauth, the cloud storage API is enabled, the appengine account used to upload has write access to the bucket. I even tried a

gsutil acl ch -u warm-particle-718@appspot.gserviceaccount.com:WRITE gs://ctrlxbucket

To be sure that the user has write access to my bucket.

Please help me to figure out what this error mean, I'm stick here since days :(

Thanks a lot

PS : If you just have some working sample of GCS ( not the google one ), I'll be happy too since there is not a lot of stuff around that topic.

Upvotes: 8

Views: 881

Answers (1)

ozarov
ozarov

Reputation: 1061

Instead of warm-particle-718@appspot.gserviceaccount.com try using XXX@developer.gserviceaccount.com (replace XXX with your application's project id - taken from "Google APIs Console Project Number" in the" Administration/Application Settings" of the admin console).

Upvotes: 1

Related Questions