0

I was testing a method by which I could upload an Image available on my Android device into a BLOB field of a mySQL table. Couple of posts I ran into spoke about broader points but I was not able to tie them all up together.

Here is a part of my code. This is written in a new Thread of a service.

    try {       
        MultipartEntityBuilder builder = MultipartEntityBuilder.create(); 
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

        builder.addTextBody(StaticVariables.filename, fileNames[i]);
        //builder.addBinaryBody(StaticVariables.image, new File (getExternalCacheDir().getParent() + File.separator + StaticVariables.bills + File.separator + fileNames[i]));
        builder.addTextBody(StaticVariables.image, getStringImage(Uri.fromFile(new File(getExternalCacheDir().getParent() + File.separator + StaticVariables.bills + File.separator + fileNames[i]))));
        httppost.setEntity(builder.build());
        HttpResponse response = httpClient.execute(httppost);
        entity = response.getEntity();

        String line = StaticVariables.emptyString;
        InputStream instream = entity.getContent();
        BufferedReader obr = new BufferedReader(new InputStreamReader(instream));
        while ((line = obr.readLine()) != null) {
             confirmed.add(line);
        }
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

THE main issue I am facing now is that on execution, an exception is being raised where it states "413: Request Entity is too large". This occurs if I pass the file in the Binary format (the commented line of code) or the Text format.

The solution to write the images on to a folder of the server has already been done by me but I am curious to know if there is some way I could get them directly on to the DB.

Other information I should share is that I am running a very basic godaddy server and hence might not have any access to change any parameters on the server.

Let me know if you would require any other information.

Appreciate any input.

Prem
  • 83
  • 1
  • 1
  • 5
  • It is unclear who is complaining that the request entry is too large. Or where. And why it goes away if you save to file. One would think it is code trying to put it in the db. – greenapps Dec 05 '16 at 19:37
  • And where is that exception? Which kind of exception? Show the catch block where you get it too. – greenapps Dec 05 '16 at 19:41
  • I have edited the code to show the catch block of the code only so that the code looks complete. However these are not the exceptions that are being triggered. When I loop through the 'response.getEntity();', I have the error presented in the HTML format. – Prem Dec 06 '16 at 03:07
  • The error. Yes. But you said it was an exception. So please show. The error message is a redponse line which you add to confirmed? Confirmed is a stringbuilder? Hard to believe. Please show in your code where you got that message. – greenapps Dec 06 '16 at 08:57

0 Answers0