1

I need get all Files from Directory on my sdCard and later send ArrayList to PHP server, but I save good my ArrayList but always it send Empty but its compile, not repots any errors.

My code

 private class MyAsyncTask extends AsyncTask<String, Integer, Double>
    {
        @Override
        protected Double doInBackground (String... params)
        {
            String datos = value.getText().toString();
            // Create a new HttpClient and Post Header
            HttpClient httpClient = getNewHttpClient();

            HttpPost httppost = new HttpPost("http://myURL.com");

            try
            {
    //.........

    return null;
        }


protected void onPostExecute (Double result)
        {
            path = Environment.getExternalStorageDirectory().toString() + "/myDirectory";


            File f = new File(path);
            File file[] = f.listFiles();
            Log.d("Files", "Size: " + file.length);

            for (int i = 0; i < file.length; i++)
            {
                Log.d("Files", "FileName:" + file[i].getName());
                etmd5.setText(etmd5.getText() + file[i].getName() + "\n");
            }

            runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    File fileArray = new File(path);
                    ArrayList<File> files = new ArrayList<File>(Arrays.asList(fileArray.listFiles()));

                    int itemCount = files.size();
                    tv_files.setText("valor:" + itemCount);

                    MultipartEntityBuilder builder = MultipartEntityBuilder.create();

                    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

                    builder.addTextBody("response", "prueba");

                    for (int i = 0; i < itemCount; i++)
                    {
                        builder.addPart("images[]", new FileBody(new File(path + "/" + num_img)));
                        num_img++;
                    }

                    HttpEntity entity = builder.build();

                }
            });
}

Something I do bad but then... I don't know how to get all files from directory to send ArrayList files... Any suggestions?

Aspicas
  • 4,498
  • 4
  • 30
  • 53
  • Very bad to start a thread in onPostExecute to do the work. Instead you should do all in doInBackground. Now first please adapt your code and show us that you can send one file. After that more files. – greenapps Mar 19 '15 at 09:05

1 Answers1

0

for the "explanation" I get that you want to send a bunch of files (meaning by file an actual file and not java.io.File)... So, you better read the files, add them to a Zip bytearray and add an entity to your post. mmh... and, please, read the File API because the first line says: An abstract representation of file and directory pathnames.

eduyayo
  • 2,020
  • 2
  • 15
  • 35