Upload file in Android webview

Posted by Sunny on Stack Overflow See other posts from Stack Overflow or by Sunny
Published on 2013-10-24T09:38:46Z Indexed on 2013/10/24 9:54 UTC
Read the original article Hit count: 1328

Filed under:
|
|
|

I have a html form like this

<form data-ajax="false" action='UserPhoto.php' class="settings" method='POST' enctype='multipart/form-data' >
<input type='file' style="height:25px" name='photo' />
<input type='hidden' name='task' value='upload'>
<input type='hidden' name='file_size' value='5000000'>

and I want to upload it by using webView posturl function, is it possible? as I know posturl can send String data by this way

String value1 = "persistent=1";
String value2 = "&email="+ 2nd_value;
String value3 = "&password="+ 3rd_value;
String postData = value1+value2+value3;
webView.postUrl("http://www.abc.php",EncodingUtils.getBytes(postData, "BASE64"));

but is it possible for me to post .png together with some string values? and I know another method using this way to upload photo

conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
conn.setRequestProperty("photo", fileName); 

but this way doesn't communicate with webview, I need to post the photo using webview as user session is kept with it.

Thanks for helping.

© Stack Overflow or respective owner

Related posts about php

Related posts about android