Vivekanand
Vivekanand

Reputation: 755

android-sending text file to server

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

Answers (1)

Rajesh
Rajesh

Reputation: 15774

Now i want to know if its possible to send this file to my localhost server

Yes, it is possible.

Looking at your original requirement, I would like to suggest you to take a look at ACRA.

Upvotes: 1

Related Questions