I am to send a song file to server through HttpPost. Currently I am using this code to send data to server
HttpPost postRequest = new HttpPost();
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("email", Splash.pref.getString("userEmail", "")));
nameValuePairs.add(new BasicNameValuePair("password", Splash.pref.getString("userPassword", "")));
nameValuePairs.add(new BasicNameValuePair("name", etName.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("title", ttfSongTitle.getText().toString()));
postRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// construct a URI objectedsta
postRequest.setURI(new URI(serviceURL));
} catch (URISyntaxException e) {
Log.e("URISyntaxException", e.toString());
}
But to send song file to server I have find this code on net but having problems to integrate these both.
String url = "http://yourserver";
File file = new File(Environment.getExternalStorageDirectory(),
"yourfile");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
} catch (Exception e) {
// show error
}
Please help me so that I could integrate these both or some other solution, so that I could send Music file to server along with other authentication data.
I am sending data to server through secure restful service.
thanks.