1

I use the following function in android but I get error "500 Java Heap Space" when calling uploader.upload().

If I called uploader.setDirectUploadEnabled(true) before uploader.upload() I get error "411 Length required" on upload() instead of error 500.

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;
        }
    }
M.Sameer
  • 3,072
  • 1
  • 24
  • 37
  • Since the error happens on the server side you should provide error entry from the log and server code where error is produced. – Peter Knego Aug 22 '12 at 08:44
  • Maybe this could help: http://stackoverflow.com/questions/15704816/google-app-engine-use-blobkey/15896876#15896876 although it does not answer your question with MediaHttpUpload, it shows a working code to upload a image easily with Resteasy –  Apr 22 '13 at 17:31

1 Answers1

0

It seems that MediaHttpUpload uses resumable protocol, which is not compatible with multipart/form-data file upload of GAE blobstore.

You should create a custom data upload servlet, that knows how to handle the resumable protocol.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154