我使用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云存储上启用了结算功能。
我用来生成上传网址的代码如下:
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的评论,我添加了所需的权限:
答案 0 :(得分:3)
我认为您没有从Google云端存储中获取您的应用程序的许可。
从文档中使用步骤number 5,如果您实际上没有使用它,请跳过弃用部分,我只是在其他地方找不到说明。