gpt4 book ai didi

java - Google App Engine 和云存储 : The AppIdentity service threw an unexpected error

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:56:50 26 4
gpt4 key购买 nike

我正在尝试按照 sample from google 设置 Google 云存储文件上传使用 GcsExampleServlet.java 。我已经完成了所有步骤,但是当我将项目部署到 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>

我已启用计费,创建了一个存储桶,但 AppIdentity 错误仍然出现。我没有 Oauth,启用了云存储 API,用于上传的应用引擎帐户对存储桶具有写入权限。我什至尝试了一个

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

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

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

非常感谢

PS:如果您只有一些 GCS 的工作样本(不是谷歌的),我也会很高兴,因为围绕该主题的内容不多。

最佳答案

尝试使用 XXX@developer.gserviceaccount.com 而不是 warm-particle-718@appspot.gserviceaccount.com(将 XXX 替换为您的应用程序的项目 ID - 采取来自管理控制台“管理/应用程序设置”中的“Google APIs 控制台项目编号”。

关于java - Google App Engine 和云存储 : The AppIdentity service threw an unexpected error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26102319/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com