我使用 1.8.2 SDK 在 Google App Engine 上创建了一个全新的项目。
我正在尝试构建一个文件上传器,在本地文件上传器工作正常,在部署它并尝试上传之后,我收到以下错误:
POST http://test2.website.appspot.com/_ah/upload/AMmfu6bj08dli8J-kL3D_xdt…cQ6YCoQx3NC1s4If-C2J1moqV7Lg/ALBNUaYAAAAAUhExcSNKV9D3-0TadzZaCtssmKinnP5T/
503 (Service Unavailable) _ah/upload/AMmfu6bj08dli8J-kL3D_xdthBPw4H3jir2X86RQ3dQPlV5LukvcH9t7OP8dK147…6YCoQx3NC1s4If-C2J1moqV7Lg/ALBNUaYAAAAAUhExcSNKV9D3-0TadzZaCtssmKinnP5T/:1
我已经在 GAE 和 Google Cloud Storage 上启用了计费功能。
我用来生成上传 url 的代码如下:
public static String getUploadUrl(HttpServletRequest req) {
String bucket = "website-uploads";
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
UploadOptions uploadOptions = UploadOptions.Builder.withGoogleStorageBucketName(bucket);
return blobstoreService.createUploadUrl("/upload", uploadOptions);
}
我正在使用普通的 servlet 来处理多部分帖子:
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
if (!SH.isLoggedIn(req)){
SH.redirectPage(req, res, 200, "/login");
return;
}
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
List<BlobKey> keys = blobs.get("file");
if (keys != null && keys.size() > 0) {
BlobKey blobKey = keys.get(0);
SH.setAttribute(req, "blobKey", blobKey.getKeyString());
} else {
SH.setAttribute(req, "uploadError", "An error occurred while uploading ...");
}
SH.setAttribute(req, "uploadUrl", getUploadUrl(req));
SH.gotoPage(req, res, 200, JSP.pageUpload);
}
然后我的表单提交:
<form id='uploadForm' action="${uploadUrl}" method="POST" enctype="multipart/form-data" >
<input id="imageUploader" name="file" type="file" />
<input type="submit" name="submitBtn" value="Upload" />
</form>
查看开/关面板,似乎启用了云存储:
我的代码有什么问题吗?或者这是 Google 需要解决的问题?
更新:
根据 Lipis 的评论,我添加了所需的权限: