Android 클라이언트에서 Google App Engine Blobstore로 이미지를 업로드하려고하는데 문제가 있습니다. 내가 찾은 관련 게시물은 모두 현재 사용되지 않는 HttpEntity를 사용합니다. 내 코드가 내 서버에서 500 오류를 반환합니다.Google App Engine Blobstore에 이미지 업로드 - Java
안드로이드 클라이언트 코드 :
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addPart("file", new FileBody(file, ContentType.MULTIPART_FORM_DATA));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(reqEntity.build());
HttpResponse httpResponse = httpclient.execute(httppost);
String response = EntityUtils.toString(httpResponse.getEntity());
서버 (앱 엔진) 코드 :
public class BlobUpload extends HttpServlet {
@Override
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
BlobKey blobKey = blobs.get("file").get(0);
res.setStatus(HttpServletResponse.SC_OK);
res.setContentType("text/plain");
if (blobKey == null) {
res.getWriter().print("failure");
} else {
res.getWriter().print("success");
}
}
}
난 아무 소용이 모두를 본 예에 따라 여러 가지 다른 permuatations을 시도했다. 나는 확실히이 문제가 방식에있다 내가 확실 해요 그래서 작동하는지 내 서블릿을 테스트 한
builder.setBoundary("--theboundary--");
httppost.addHeader("Content-Type", "multipart/form-data; boundary=--theboundary--");
이 내 클라이언트 코드에 다음 행을 추가하여 멀티 파트/양식 - 데이터에 대한 Content-Type을 설정 포함 내 서버에 내 데이터를 게시하고 있습니다. 나는 MIME 및 App Engine 문서 (둘 다 제한적이라고 생각하는)를 훑어 보았고 해결책을 찾지 못했습니다. 모든 생각/제안 또는 작업 예제는 크게 감사하겠습니다.