Android : How send media files in Android by Post method?

on Sunday, October 12, 2014


My intention is to send small audio files less than megabyte to a php file, for storage in a mysql database.


First I would like to know in general there is a problem doing it in this way.


To begin to solve this problem, I need to first know how to send a file from Android by a POST request.


The following code can send a POST request to a PHP file, but on the value of the request can only send strings.


Is there any way to modify this code to send a file that stored in a specific folder on Android device?



HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("www.myserver.com/audio.php");


List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("myKey", "Value"));
httppost.setEntity(new UrlEncodedFormEntity( nameValuePairs));
httpclient.execute(httppost);

0 comments:

Post a Comment