2013-08-18 258 views
0

我使用1.8.2 SDK在Google App Engine上創建了一個全新的項目。GAE:文件上傳失敗

我試圖建立一個文件上傳,本地文件上傳正常工作,部署它,並試圖上傳,我發現了以下錯誤後:

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

然後我的形式doind提交:

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

查看開/關面板,看起來雲存儲已啓用: enter image description here

我的代碼有什麼問題,或者這是Google需要解決的問題嗎?

更新:

基於立卑的評論,我已經添加了所需的權限:

enter image description here

回答

3

我想你沒有給從谷歌雲存儲許可應用程序。

從文檔中使用步驟number 5,如果您實際上沒有使用它,請跳過棄用部分,但我沒有在其他地方找到說明。

+0

我在雲存儲控制檯中添加了「CAN EDIT」權限,但它顯示「已發送邀請,正在等待響應。」我是否需要在某處批准或自動發生? –

+0

我試着再次添加它,第二次工作,感謝指針:-) –