I need to know the full source code of how to upload doc,txt,pdf files into mysql server through android. Following below code is uploading strings to server, I need to know what way i can upload file along with those nameValuePairs.
class PostJobAsync extends AsyncTask<String, String, String> {
//String result;
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = ProgressDialog.show(getActivity(), "",
"Submitting. Please wait...", true);
dialog.show();
}
@Override
protected String doInBackground(String... params) {
InputStream is = null;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("postifontitle", positiontitle));
nameValuePairs.add(new BasicNameValuePair("destcription", description));
nameValuePairs.add(new BasicNameValuePair("technwical_skills", techskillsval));
nameValuePairs.add(new BasicNameValuePair("sofrt_skills", softskillsval));
nameValuePairs.add(new BasicNameValuePair("raate", rate));
nameValuePairs.add(new BasicNameValuePair("posteedby", getUser_id));
nameValuePairs.add(new BasicNameValuePair("hotjtob", hotjobornot));
nameValuePairs.add(new BasicNameValuePair("starttdate", startdate));
nameValuePairs.add(new BasicNameValuePair("dommain", domain));
nameValuePairs.add(new BasicNameValuePair("rellocation", willingtorelocateval));
// if (selectedFilePath != null)
// {
// nameValuePairs.add(new BasicNameValuePair("attachment", selectedFilePath));
// }
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://10.0.3.2/Jummusapi/post-job");
// HttpPost httpPost = new HttpPost("http://www.nthmile.com/xpressjobs/rest/postjob");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
int code = response.getStatusLine().getStatusCode();
String rescode = String.valueOf(code);
//result=is.toString();
return rescode;
} catch (MalformedURLException e) {
return e.toString();
} catch (IOException e) {
return e.toString();
}
}