i need to upload a very small sized .xml file to a php script. This script will parse the file, create some stuff on a map, and then the application will display the result.
The problem is that, if i have to upload a file with an html page, i create a form, put an input field with "name=userfile" and then server side i find it in $_FILES['userfile'].
How to do this in android? with string is very simple with
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add("key", "value");
but now?
this is my code client side but no file seems to hit the server:
final String url = "http://www.blablabladasdasd/mysite/test.php";
String selected = getIntent().getStringExtra("com.example.ghghgh.filename");
final File file = new File("/storage/sdcard0/myFolder/"+selected + ".xml");
Log.i("FILE SIZE: ", "" + file.length());
final WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.getSettings().setSaveFormData(true);
mWebView.setWebViewClient(new MyWebViewClient());
Thread thread = new Thread()
{
public void run()
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
client.getParams().setParameter("userfile", file);
try
{
HttpResponse response = client.execute(post);
String res = EntityUtils.toString(response.getEntity());
Log.i("RESPONSE: ", res);
mWebView.loadData(res, "text/html", HTTP.UTF_8);
}
catch(ClientProtocolException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
};
thread.start();
try
{
thread.join();
}
catch(InterruptedException e)
{
e.printStackTrace();
}