来自Android的Google Cloud Endpoints API调用的错误413(请求实体太大) [英] Error 413 (Request Entity Too Large) on a Google Cloud Endpoints API call from Android
问题描述
我有以下Google Cloud Endpoints API方法。
I have a Google Cloud Endpoints API method as follows.
@ApiMethod(name = "setImage", httpMethod = ApiMethod.HttpMethod.POST)
public void setImage(HttpServletRequest httpRequest,
com.google.appengine.api.users.User appEngineUser,
@Named("image") String image)
throws IOException, OAuthRequestException, ForbiddenException,
com.google.api.server.spi.response.NotFoundException {
// Write the image text to a pojo and save the pojo in the datastore.
}
我从这个API生成iOS和Android的客户端库。在这两个移动应用程序中,我使用相机拍摄照片,必要时从相机中重新取样位图,将其压缩为JPEG并使用数据URI方案将其编码为字符串。
I generate client libraries for iOS and Android from this API. In both mobile apps, I use the camera to take a photo, resample the bitmap from the camera down if necessary, compress it to JPEG and encode it as a string using the data URI scheme.
在iOS上,一切正常。我最终上传了大约436K个字符。但是,在Android上,我从服务器获得了413(Request Entity Too Large)HTTP响应。即使我将图像重新采样到我只为JPEG发送大约39K的点,也会发生这种情况。
On iOS, this all works just fine. I end up uploading about 436K characters. On Android, however, I get a "413 (Request Entity Too Large)" HTTP response from the server. This happens even if I resample the image right down to the point where I'm only sending about 39K for the JPEG.
为什么? Android的堆栈跟踪就是这样。
Why? The stack trace for Android is this.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 413 Request Entity Too Large
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
08-24 15:39:26.046 26980-26980/cc.biketracker.android W/System.err﹕ at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
08-24 15:39:26.046 26980-26980/cc.biketracker.android W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
08-24 15:39:26.046 26980-26980/cc.biketracker.android W/System.err﹕ at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at cc.biketracker.android.task.SetDeviceBikeImageTask.doInBackground(SetDeviceBikeImageTask.java:45)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at cc.biketracker.android.task.SetDeviceBikeImageTask.doInBackground(SetDeviceBikeImageTask.java:16)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-24 15:39:26.047 26980-26980/cc.biketracker.android W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
推荐答案
我相信这是因为您使用的是图像作为URL参数而不是资源。我建议将 @Named(image)字符串图像
更改为 SetImageRequest请求
并创建一个 SetImageRequest
包含编码String的类。它可能适用于iOS而不是Android的原因是因为iOS客户端使用JSON-RPC,它根本不使用URL参数。
I believe it's because you're using image as a URL parameter rather than as the resource. I'd suggest changing @Named("image") String image
to be SetImageRequest request
and make a SetImageRequest
class which contain the encoded String. The reason it probably works on iOS and not Android is because the iOS client uses JSON-RPC, which doesn't use URL parameters at all.
这篇关于来自Android的Google Cloud Endpoints API调用的错误413(请求实体太大)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!