apache - How post file to android HttpUrlConnection internal server 500 -


i trying upload image server via httpurlconnection it's not working.

return internal server 500

anyone can me? thats postman captures 1: http://i62.tinypic.com/6e279j.png 2: http://oi62.tinypic.com/6e279j.jpg

and code block

 url = new url(urls[0]);                 // post header             file image = new file(outfile);                 httpurlconnection con = (httpurlconnection)                         url.openconnection();                 con.setdoinput(true);                 con.setdooutput(true);                 con.setrequestmethod("post");                 con.setrequestproperty("connection", "keep-alive");                 con.setrequestproperty("apikey", apikey);                 con.setrequestproperty("authkey", authkey);                 con.setrequestproperty("content-disposition","form-data; name=\"fileupload\"filename="+image.getname());                 con.setrequestproperty("content-type","image/jpg");                 con.setrequestproperty("content-type", "multipart/form-data; boundary=----webkitformboundary8faidy4eudwgpyca");                  // post body (copied file stream)                 int i;                 byte[] buff = new byte[8192];                 fileinputstream fis = new fileinputstream(image);                 outputstream os = con.getoutputstream();                 while((i = fis.read(buff)) == 8192)                     os.write(buff);                 os.write(buff, 0, i);                 os.flush();                 os.close();                 con.connect();                 log.w("response",con.getresponsemessage()+" - " +con.getresponsecode() +" - "+ image.getname());                 // read response (still needed)                 string text = null; 

finally server side var _uploaddirectory = path.combine(pathprovider.getrootpath(), "upimages"); var _filename = helper.getguid();//path.changeextension(helper.getguid(), "png");

            if (request.files.count() != 1)                 return new naberresponse("error", "invalid parameters");              try             {                 if (!directory.exists(_uploaddirectory))                     directory.createdirectory(_uploaddirectory);                  var _file = request.files.first();                  using (var _filestream = new filestream(path.combine(_uploaddirectory, path.changeextension(_filename, "jpg")), filemode.create))                 {                     _file.value.copyto(_filestream);                 }                  return new naberresponse(pdata: new { media_url = string.format("{0}/post/image/{1}", request.url.sitebase, _filename) }); 


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -