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.