我正在尝试按照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>
我启用了结算功能,创建了一个存储桶但仍然出现了AppIdentity错误。我没有Oauth,云存储API已启用,用于上传的appengine帐户具有对存储桶的写入权限。我甚至试过了
gsutil acl ch -u warm-particle-718@appspot.gserviceaccount.com:WRITE gs://ctrlxbucket
确保用户具有对我的存储桶的写入权限。
请帮我弄清楚这个错误是什么意思,我从天开始就坚持到这里:(
非常感谢
PS:如果你只有一些GCS的工作样本(不是谷歌版),我也会很高兴,因为围绕这个话题没有很多东西。
答案 0 :(得分:1)
而不是warm-particle-718@appspot.gserviceaccount.com尝试使用XXX@developer.gserviceaccount.com(将XXX替换为您的应用程序的项目ID - 采取 来自管理控制台“管理/应用程序设置”中的“Google API控制台项目编号”。