node.js - Why isn't working my uploader from android to NodeJS server? -


i tried code, message http response is: 404 not found

@suppresslint("sdcardpath") public class mainactivity extends activity {  textview messagetext; button uploadbutton; int serverresponsecode = 0; progressdialog dialog = null;  string uploadserveruri = null;  /* filepath */ final string uploadfilepath = "/mnt/sdcard/"; final string uploadfilename = "test.jpg";  @override public void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      uploadbutton = (button)findviewbyid(r.id.uploadbutton);     messagetext  = (textview)findviewbyid(r.id.messagetext);      messagetext.settext("uploading file path :- '/mnt/sdcard/"+uploadfilename+"'");      uploadserveruri = "http://192.168.0.12:9999";      uploadbutton.setonclicklistener(new onclicklistener() {                     @override         public void onclick(view v) {              dialog = progressdialog.show(mainactivity.this, "", "uploading file...", true);              new thread(new runnable() {                     public void run() {                          runonuithread(new runnable() {                                 public void run() {                                     messagetext.settext("uploading started.....");                                 }                             });                                                 uploadfile(uploadfilepath + "" + uploadfilename);                      }                   }).start();                     }         }); }  public int uploadfile(string sourcefileuri) {         string filename = sourcefileuri;        httpurlconnection conn = null;       dataoutputstream dos = null;         string lineend = "\r\n";       string twohyphens = "--";       string boundary = "/upload";       int bytesread, bytesavailable, buffersize;       byte[] buffer;       int maxbuffersize = 1 * 1024 * 1024;        file sourcefile = new file(sourcefileuri);         if (!sourcefile.isfile()) {             dialog.dismiss();              log.e("uploadfile", "source file not exist :"                                +uploadfilepath + "" + uploadfilename);             runonuithread(new runnable() {                public void run() {                    messagetext.settext("source file not exist :"                            +uploadfilepath + "" + uploadfilename);                }            });              return 0;        }       else       {            try {                    // open url connection servlet                fileinputstream fileinputstream = new fileinputstream(sourcefile);                url url = new url("http://192.168.0.12:9999");                 // open http  connection  url                conn = (httpurlconnection) url.openconnection();                 conn.setdoinput(true); // allow inputs                conn.setdooutput(true); // allow outputs                conn.setusecaches(false); // don't use cached copy                conn.setrequestmethod("post");                conn.setrequestproperty("connection", "keep-alive");                conn.setrequestproperty("enctype", "multipart/form-data");                conn.setrequestproperty("content-type", "multipart/form-data;boundary=" + boundary);                conn.setrequestproperty("uploaded_file", filename);                  dos = new dataoutputstream(conn.getoutputstream());                 dos.writebytes(twohyphens + boundary + lineend);                 dos.writebytes("content-disposition: form-data; name=uploaded_file;+filename="                        + filename + "" + lineend);                 dos.writebytes(lineend);                 // create buffer of  maximum size                bytesavailable = fileinputstream.available();                  buffersize = math.min(bytesavailable, maxbuffersize);                buffer = new byte[buffersize];                 // read file , write form...                bytesread = fileinputstream.read(buffer, 0, buffersize);                   while (bytesread > 0) {                  dos.write(buffer, 0, buffersize);                  bytesavailable = fileinputstream.available();                  buffersize = math.min(bytesavailable, maxbuffersize);                  bytesread = fileinputstream.read(buffer, 0, buffersize);                     }                 // send multipart form data necesssary after file data...                dos.writebytes(lineend);                dos.writebytes(twohyphens + boundary + twohyphens + lineend);                 // responses server (code , message)                serverresponsecode = conn.getresponsecode();                string serverresponsemessage = conn.getresponsemessage();                 log.i("uploadfile", "http response : "                        + serverresponsemessage + ": " + serverresponsecode);                 if(serverresponsecode == 200){                     runonuithread(new runnable() {                         public void run() {                              string msg = "file upload completed.\n\n see uploaded file here : \n\n"                                           +" http://www.androidexample.com/media/uploads/"                                           +uploadfilename;                              messagetext.settext(msg);                             toast.maketext(mainactivity.this, "file upload complete.",                                           toast.length_short).show();                         }                     });                                }                     //close streams //                fileinputstream.close();                dos.flush();                dos.close();            } catch (malformedurlexception ex) {                dialog.dismiss();                 ex.printstacktrace();                runonuithread(new runnable() {                   public void run() {                       messagetext.settext("malformedurlexception exception : check script url.");                       toast.maketext(mainactivity.this, "malformedurlexception",                                                            toast.length_short).show();                   }               });                log.e("upload file server", "error: " + ex.getmessage(), ex);             } catch (exception e) {                dialog.dismiss();                 e.printstacktrace();                runonuithread(new runnable() {                   public void run() {                       messagetext.settext("got exception : see logcat ");                       toast.maketext(mainactivity.this, "got exception : see logcat ",                                toast.length_short).show();                   }               });               log.e("upload file server exception", "exception : "                                                + e.getmessage(), e);             }           dialog.dismiss();                  return serverresponsecode;        }}} 

can me university thesis? moreover, if can how can save file nodejs , mongodb, him!


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -