I want to send video to server. What I am doing is I am converting the video into a "ToBase64String" and sending to my server via JObject. My problem is the sending of the video is too slow about 20 to 30 mins depending on the file size and connection to server speed. How can I improve the speed or is there a better way to send a video to a server. I am using Xamarin and PHP. I am also using ffmpeg to convert the video into a smaller size when saving the video to the server's hard drive. I think the sending of the base64string is fast the processing of the video(My PHP) is slow because when I use break in my code the app is waiting for the response from my server(crresponse.IsSuccessStatusCode). I think it is either the conversion of the video using ffmpeg or the creation of the video itself file_put_contents
Xamarin Code (this is where I convert and send the video)
byte[] crVideoData = File.ReadAllBytes(crvideo);
crvid = Convert.ToBase64String(crVideoData);
JObject crjson = new JObject
{
{ "Video", crvid }
}
HttpClient crclient = new HttpClient();
var crresponse = await crclient.PostAsync(crlink, new StringContent(crjson.ToString(), Encoding.UTF8, crcontentType));
if (crresponse.IsSuccessStatusCode)
{
await conn.QueryAsync<CAFTable>("UPDATE tblCaf SET LastSync = ? WHERE CAFNo = ?", DateTime.Parse(current_datetime), crcafNo);
}
PHP code (this is where I receive and decode the base64string)
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);
$Video = $json_obj->Video;
$ContactID = $json_obj->ContactID;
$video_decode = base64_decode($Video);
$video_filename = __DIR__ . '/uploads/'. $CAF . '_'.$CafDate.'_VID.mp4';
$video_dbfilename = './uploads/'. $CAF . '_'.$CafDate.'_VID.mp4';
$save_video = file_put_contents($video_filename, $video_decode);
if(file_exists($video_filename)) {
$temp_video_filename = __DIR__ . '/tmp/'. $CAFNo . '_'.$CafDate.'_VID.mp4';
exec('ffmpeg -i '.$video_filename.' -c:v libx264 '.$temp_video_filename.' 2>&1');
unlink($video_filename);
rename($temp_video_filename, $video_filename);
}