1
votes

in my android application i encode a video as base 64 like this.

File file=new File(path);
InputStream is = new FileInputStream(file);
int length = (int)file.length();
byte[] bytes = new byte[length];
int a=is.read(bytes,0,length);
String str = Base64.encodeToString(bytes, 0);
is.close();
//send the string to my server....

PHP
$str=$_POST['str'];
$var=base64_decode($str);
$fp = fopen('2013-02-21_14-52-35_968.mp4', 'w');
fwrite($fp,$var);
fclose($fp);

So when the video file is Written, i cant open it. How i can correctly encode a video and decode it from PHP? or what im missing thanks in advanced.

1
Base64 adds at least 1/3 to the payload. Why not just send it binary, possibly in chunks, so it's a bit more resilient to flakey (mobile) networks? - 323go
well the problem was i read only a few bytes so i loop that and from the server side i have to open the file, encode each chunk, add that to the file, create the file. - user2033349

1 Answers

1
votes

I solve my problem, the issue was I only encode one part of the file. Here my solution:

$fp=fopen("/address".$filename,'w')
 while($row=mysql_fetch_array($getChunks)){
 $chuncks=$row['chunkpart'];
 $var=base64_decode($chunks);
  fwrite($fp,$var)
 }