【问题标题】:getting 500 from Blobstore从 Blobstore 获得 500
【发布时间】:2013-04-24 00:44:57
【问题描述】:

这里是事件的项目符号列表:

  • 我的 android 应用程序将 blob 发送到 Blobstore。
  • 从应用引擎控制台,我可以在 Blob Viewer 中看到我的 blob,所以我知道我的 blob 已保存
  • 但是 Blobstore 不调用回调 url,而是调用
  • Blobstore 向我的 Android 应用返回 500

所以我无法获取数据存储区的 blob 密钥。

http postmyImage的代码是一个字节数组:

HttpClient httpClient = new DefaultHttpClient();
        HttpPost postRequest = new HttpPost(url);
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        try {
             reqEntity.addPart("title", new StringBody(title));
        reqEntity.addPart("caption", new StringBody(caption));
            ByteArrayBody myBlob = new ByteArrayBody(myImage, "myImage.png");
            reqEntity.addPart("myBlob", myBlob);
            ByteArrayBody secBlob = new ByteArrayBody(secBlobImage, "secBlobImage.png");
            reqEntity.addPart("secBlob", secBlob);
        } catch (Exception e) {
            e.printStackTrace();
        }
        postRequest.setEntity(reqEntity);
        try {
            HttpResponse response = httpClient.execute(postRequest);
            System.out.println("RESPONSE CODE::: " + response.getStatusLine().getStatusCode());
            System.out.println("REASON CODE::: " + response.getStatusLine().getReasonPhrase());
        } catch (Exception e) {
            e.printStackTrace();
        }

在 android 发起对 blobstore 的调用后,我从 logCat 得到以下咆哮:

04-30 00:59:15.922: I/APACHE HTTP (thCr=4674) - NafHttpAuthStrategyDefault(8796): (thUse=4674) NafHttpAuthStrategyDefault()
04-30 00:59:15.922: I/APACHE HTTP (thCr=4674) - KeeperManager(8796): (thUse=4674) INITIALIZATION of shared resources
04-30 00:59:15.922: I/APACHE HTTP (thCr=4674) - AndroidContextProviderImpl(8796): (thUse=4674)    currentActivityThread=null
04-30 00:59:15.930: I/APACHE HTTP (thCr=4674) - GbaSupportIndicatorRequestUpdaterDefault(8796): (thUse=4674) GbaSupportIndicatorRequestUpdaterAbstract()   userHeaderPredefined=Apache-HttpClient/UNAVAILABLE (java 1.4)
04-30 00:59:15.946: I/APACHE HTTP (thCr=4674) - NafHttpAuthStrategyDefault(8796): (thUse=4674)    cached value : gbaSupportIsPossible=null
04-30 00:59:15.946: I/APACHE HTTP (thCr=4674) - NafHttpAuthStrategyDefault(8796): (thUse=4674)    The current context is NOT a context of GBA service.
04-30 00:59:15.946: I/APACHE HTTP (thCr=4674) - GbaSupportPermissionRequestCheckerImpl(8796): (thUse=4674) isCurrentProcessRequestedGba()#finished   result=false
04-30 00:59:15.946: I/APACHE HTTP (thCr=4674) - GbaSupportPermissionRequestCheckerImpl(8796): (thUse=4674) isCurrentProcessAllowedToUseGba()#started   result=false
04-30 00:59:15.946: I/APACHE HTTP (thCr=4674) - NafHttpAuthStrategyDefault(8796): (thUse=4674)    The GBA permission wasn't requested for this process.
04-30 00:59:15.954: I/APACHE HTTP (thCr=4674) - NafHttpAuthStrategyDefault(8796): (thUse=4674) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
04-30 00:59:15.954: I/APACHE HTTP (thCr=4674) - NafRequestExecutorWrapperRedirectionHandler(8796): (thUse=4674)    It isn't GBA flow, redirection responses are not handled.
04-30 00:59:20.688: I/APACHE HTTP (thCr=4674) - NafHttpAuthStrategyDefault(8796): (thUse=4674)    cached value : gbaSupportIsPossible=false
04-30 00:59:20.688: I/System.out(8796): RESPONSE CODE::: 500
04-30 00:59:20.696: I/System.out(8796): REASON CODE::: Internal Server Error

编辑:

非常感谢@Teshte 和@ShivanRaptor 的提问。我以为我的服务器没有被击中。但他们的问题让我意识到确实如此。所以当我查看服务器日志时,我发现在下面的代码中BlobKey titleKey = blobs.get("title").get(0) 处有一个java.lang.NullPointerException。 NPE 发生在 android 作为StringBody 发送的元素上。我还没有想出如何修复 NPE。

代码:

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
        Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
        BlobKey titleKey = blobs.get("title").get(0);
…

res.sendRedirect("/");
}

【问题讨论】:

  • 你能出示你的代码吗?
  • 代码只是典型的http post。我已经添加了它。 @ShivanRaptor
  • 这是 Android 代码...GAE 代码在哪里?
  • @Teshte 非常感谢这个问题,它让我找到了原因。我已经更新了帖子。任何想法如何解决根本原因?
  • 你可能会因为Map&lt;String, List&lt;BlobKey&gt;&gt; blobs = blobstoreService.getUploads(req);而获得NPE ..尝试看看这张地图包含什么......

标签: android google-app-engine blobstore


【解决方案1】:

我将所有对象作为ByteArrayBody 发送,而不是将一些对象编码为StringBody

【讨论】:

    猜你喜欢
    • 2014-05-22
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-28
    相关资源
    最近更新 更多