Cargando archivo en el servidor apache usando httppost

I am currently trying to upload file / images on to my apache server from AVD. I'm not getting any errors when i execute my code, but image is not uploaded to the server. I've changed permission of the folder on the apache server which is to writable and editable by other users. I am having trouble with this, please help. Follow is my code

This code gets the image and decode into bitmap.

   bmp = BitmapFactory.decodeFile(filePath);

Following is code that i run to upload files to the server

ByteArrayOutputStream bos = new ByteArrayOutputStream();
Bitmap tmpbmp = bmp;
tmpbmp.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(url);
ByteArrayBody bab = new ByteArrayBody(data, "test.jpg");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploaded", bab);
reqEntity.addPart("photoCaption", new StringBody("aaaa"));
HttpResponse httpResponse = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new  InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();

            while ((sResponse = reader.readLine()) != null) {
                s = s.append(sResponse);

            Log.i("wi", "Response: " + s);

        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            Log.i("wi", "Encoding failed: " + e);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            Log.i("wi", "client protocol exception!: " + e);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.i("wi", "IO Exception!: " + e);

And i am getting response from Log.i("wi", "Response: " + s); =

    Response: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html> <head>  
<title>Index of /images</title> </head> <body><h1>Index of /images</h1><ul><li><a 
href="/es/"> Parent Directory</a></li></ul></body></html>

It hasn't uploaded the file.

preguntado el 04 de julio de 12 a las 08:07

2 Respuestas

Estoy utilizando Apache's commons-net-ftp library to upload my song file to the server...i am giving you the code....Try using this..






    import android.util.Log;

    public class MyOwn {

        public void goforIt(){

            FTPClient con = null;

                con = new FTPClient();
                con.connect("");                 // Its dummy Address

                if (con.login("uju495", "Stevejobs!!"))
                    con.enterLocalPassiveMode();                   // Very Important

                    con.setFileType(FTP.BINARY_FILE_TYPE);        //  Very Important
                    String data = "/sdcard/Vivekm4a.m4a";

                    FileInputStream in = new FileInputStream(new File(data));
                    boolean result = con.storeFile("/Ads/Vivekm4a.m4a", in);
                    if (result) Log.v("upload result", "succeeded");
            catch (Exception e)


Respondido 04 Jul 12, 08:07

Hey man, this is so amazing. I wasn't thinking about using FTP library that's available online at all. I thank you so much for letting me using this code and letting me know about FTP thank you so much. - Jason

Well in return am i privileged to get some points as appreciation from u.......he he he he...... - Kumar Vivek Mitra

It seems that server is returning directory listing. You need to code a server side script to receive the file. Have you done this?

Aquí hay un ejemplo:

Respondido 04 Jul 12, 08:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.