java – Google Appengine和云存储:AppIdentity服务引发了意外错误

栏目: 后端 · 发布时间: 7年前

内容简介:使用GcsExampleServlet.java设置Google云端存储文件上传.我已完成所有步骤,但当我将项目部署到aggengine并尝试在GCS中上传简单文本时,它会失败并显示以下日志:仍然,代码中没有任何复杂的…在web.xml中我已经配置了servlet:这是servlet GcsExampleServlet.java(与google示例完全相同):
我正在尝试按照 sample from google

使用GcsExampleServlet.java设置Google云端存储文件上传.我已完成所有步骤,但当我将项目部署到aggengine并尝试在GCS中上传简单文本时,它会失败并显示以下日志:

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)
(...)

仍然,代码中没有任何复杂的…在web.xml中我已经配置了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>

这是servlet GcsExampleServlet.java(与google示例完全相同):

@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();
    }
  }
}

这是我的upload.html文件:

<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>

我启用了Billing,创建了一个存储桶但仍然出现了AppIdentity错误.我没有Oauth,云存储API已启用,用于上传的appengine帐户具有对存储桶的写入权限.我甚至试过了

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

确保用户具有对我的存储桶的写入权限.

请帮我弄清楚这个错误是什么意思,我坚持这里几天:(

非常感谢

PS:如果你只有一些GCS的工作样本(不是google的样本),我也会很开心,因为围绕这个话题没有很多东西.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Artificial Intelligence

Artificial Intelligence

Stuart Russell、Peter Norvig / Pearson / 2009-12-11 / USD 195.00

The long-anticipated revision of this #1 selling book offers the most comprehensive, state of the art introduction to the theory and practice of artificial intelligence for modern applications. Intell......一起来看看 《Artificial Intelligence》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具