I'm trying send a large video to PHP server from App Android, but I can't because always It's reports java.lang.OutOfMemoryError.
I try to use, Apache components and HttpURLConnection but I can't send it...
I read a lot of similar questions but I can't do that.
my code
private class MyAsyncTask extends AsyncTask<String, Integer, Double>
{
@Override
protected Double doInBackground (String... params)
{
String datos = value.getText().toString();
// Create a new HttpClient and Post Header
HttpClient httpClient = getNewHttpClient();
HttpPost httppost = new HttpPost("My url");
try
{
String youFilePathVideo = Environment.getExternalStorageDirectory()
+ "/project/video.mp4";
File file = new File(youFilePathVideo);
byte[] fileData = new byte[(int) file.length()];
DataInputStream dis = new DataInputStream(new FileInputStream(file));
dis.readFully(fileData);
dis.close();
strBaseVideo=Base64.encodeToString(fileData, 0);
JSONObject video = new JSONObject();
try
{
video.put("video.mp4", strBaseVideo);
} catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONArray jsonArray = new JSONArray();
jsonArray.put(video);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("video", video.toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpClient.execute(httppost);
responseBody = EntityUtils.toString(response.getEntity());
Please, I need help, thanks.