Androidで次の関数を使用していますが、呼び出し時に「500 Java Heap Space」というエラーが発生しますuploader.upload()
。
エラー500の代わりに「411 Length required」というエラーが表示されるuploader.setDirectUploadEnabled(true)
前に電話した場合。uploader.upload()
upload()
public static String uploadImage(Context context, String file, MediaHttpUploaderProgressListener progressListener)
throws Exception {
// The file is something like : /mnt/sdcard/wallpapers/image.jpg
File mediaFile = new File(file);
HttpTransport transport = new NetHttpTransport();
HttpRequestFactory factory = transport.createRequestFactory(null);
//obtain the upload url
GenericUrl getUploadUrl = new GenericUrl(Util.getBaseUrl(context)
+ "/myapp/blobservice?get-key");
HttpRequest request = factory.buildGetRequest(getUploadUrl);
HttpResponse response1 = request.execute();
String postUrl = convertStreamToString(response1.getContent()).trim();
// the returned post url when using the development server is something like : //http://192.168.1.4:8888/_ah/upload/agd5YWRnZXQychwLEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18Y2wUM
InputStreamContent mediaContent = new InputStreamContent("image/jpeg",
new BufferedInputStream(new FileInputStream(mediaFile)));
mediaContent.setLength(mediaFile.length());
MediaHttpUploader uploader = new MediaHttpUploader(mediaContent,transport, null);
uploader.setProgressListener(progressListener);
//the following line produces exception "500 Java heap space" on the local server
//on the remote server I get "500: Internal server error"
HttpResponse response = uploader.upload(new GenericUrl(postUrl));
if (!response.isSuccessStatusCode()) {
throw new Exception("Uploading image failed.");
} else {
String blobKey = convertStreamToString(response.getContent()).trim();
return blobKey;
}
}