Reputation: 755
I have an android application in which if I there is any exception it will write it into a file (File is stored in Device's internal memory)..... Now i want to know if its possible to send this file to my localhost server.
Thanks in advance
EDIT: The code below is what i use to upload an image...
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Bitmap bm=bitmap;
bm.compress(CompressFormat.PNG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
String url="192.168.1.1**";
HttpPost postRequest = new HttpPost(url+"uploadimage");
ByteArrayBody bab = new ByteArrayBody(data, imageName);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploadfile", bab);
//reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
System.out.println("Response: " + s);
} catch (Exception e) {
// handle exception here
Log.e(e.getClass().getName(), e.getMessage());
}
similarly i want to upload a file (text file).
Upvotes: 0
Views: 1047