php - Android AsyncTask Upload Files -


i want upload number of files stored on android device seems stuck in doinbackground method of asynctask. no errors. dialog popsup , stays active eliminated dialog , no effect. other part of project decode json files uploaded , store them in database thats later.

    /********************upload gpsdata*************************************/ class uploadgpsdata extends asynctask<void, void, void>{      networkinfo net;      mainactivity uactivity;      httpurlconnection connection = null;     dataoutputstream outputstream = null;     datainputstream inputstream = null;      string folderpath;     string arrayoffiles[];     file root;     file allfiles;      string urlserver = "http://urluploadscriptaddress.php";     string lineend = "\r\n";     string twohyphens = "--";     string boundary =  "*****";      int bytesread, bytesavailable, buffersize;     byte[] buffer;     int maxbuffersize = 1*1024*1024;      url url;       progressdialog pdialog = new progressdialog(mainactivity.this);        @override     protected void onpreexecute() {           log.d(" uploadgpsdata","onprerequest");              pdialog.setmessage("uploading gps data. please wait...");             pdialog.setindeterminate(false);             pdialog.setcancelable(true);             pdialog.show();       }      @override     protected void doinbackground(void... params) {           log.d(" uploadgpsdata","doinbackground");          root = environment.getexternalstoragedirectory();           //pathtoourfile = root.getabsolutepath()+"/beagle data/07-09-2013_16-21-30.json";          folderpath = root.getabsolutepath()+"/beagle data/";          allfiles = new file(folderpath);          arrayoffiles = allfiles.list();              for(int = 0; < arrayoffiles.length; i++){              log.d("file names", arrayoffiles[i].tostring());             //file filename = new file(arrayoffiles[i].tostring());             try {                 url = new url(urlserver);             } catch (malformedurlexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }              try {                 connection = (httpurlconnection) url.openconnection();             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }              // allow inputs & outputs             connection.setdoinput(true);             connection.setdooutput(true);             connection.setusecaches(false);              // enable post method             try {                 connection.setrequestmethod("post");             } catch (protocolexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }             connection.setrequestproperty("connection", "keep-alive");             connection.setrequestproperty("content-type", "multipart/form-data;boundary="+boundary);             try{              fileinputstream fileinputstream = new fileinputstream(new file(folderpath+arrayoffiles[i].tostring()) );             try {                 outputstream = new dataoutputstream( connection.getoutputstream() );             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }             outputstream.writebytes(twohyphens + boundary + lineend);             outputstream.writebytes("content-disposition: form-data; name=\"uploadedfile\";filename=\"" + folderpath+arrayoffiles[i].tostring() +"\"" + lineend);             outputstream.writebytes(lineend);              bytesavailable = fileinputstream.available();             buffersize = math.min(bytesavailable, maxbuffersize);             buffer = new byte[buffersize];              // read file             bytesread = fileinputstream.read(buffer, 0, buffersize);              while (bytesread > 0){                 outputstream.write(buffer, 0, buffersize);                 bytesavailable = fileinputstream.available();                 buffersize = math.min(bytesavailable, maxbuffersize);                 bytesread = fileinputstream.read(buffer, 0, buffersize);              }              outputstream.writebytes(lineend);             outputstream.writebytes(twohyphens + boundary + twohyphens + lineend);              //int serverresponsecode = connection.getresponsecode();             //string serverresponsemessage = connection.getresponsemessage();              // responses server (code , message)             //serverresponsecode = connection.getresponsecode();             //serverresponsemessage = connection.getresponsemessage();              fileinputstream.close();             outputstream.flush();             outputstream.close();             } catch(exception e){                 e.printstacktrace();             }          }       return null;     }      protected void onpostexecute() {           log.d(" uploadgpsdata","onpost");          pdialog.dismiss();          txtuploadstatus = (textview) findviewbyid(id.txtuploadstatus);          txtuploadstatus.settext("upload achieved");     } } /********************end of uploadgpsdata*************************************/ 

php script below: error log empty assuming stuck on android application

<?php $target_path  = "./";  $target_path = $target_path . basename( $_files['uploadedfile']['name']);  $file = basename( $_files['uploadedfile']['name']);  move_uploaded_file($_files['uploadedfile']['tmp_name'], $target_path) ?> 

you not implement @override onpostexecute.

modify onpostexecute assignature this:

@override protected void onpostexecute(void result) { 

this resolve problem. happening: not overriding onpostexecute asynctask method, creating new one.


Comments