How do I upload Audio+video as one to server? - recordrtc

How to upload RecordRTC based audio+video recordings to server in a single file format?
RecordRTC seems generating two separate files: one for audio (as WAV) and another one for video (as WebM). How to upload both files simultaneously on a PHP server?

Since Chrome >=49, RecordRTC is now using MediaRecorder API to support microphone+webcam recordings into single WebM file format.
Here is how to record both audio+video into single WebM (this works both on Chrome >= 49 and Firefox >= 38)
<script src="https://cdn.WebRTC-Experiment.com/gumadapter.js"></scrip>
<script>
var recorder;
function successCallback(audioVideoStream) {
recorder = RecordRTC(audioVideoStream, {
type: 'video',
mimeType: 'video/webm',
bitsPerSecond: 512 * 8 * 1024
});
recorder.startRecording();
}
function errorCallback(error) {
// maybe another application is using the device
}
var mediaConstraints = {
video: true,
audio: true
};
navigator.mediaDevices.getUserMedia(mediaConstraints).then(successCallback).catch(errorCallback);
document.querySelector('#btn-stop-recording').onclick = function() {
if (!recorder) return;
recorder.stopRecording(function() {
var audioVideoBlob = recorder.blob;
// you can upload Blob to PHP/ASPNET server
uploadBlob(audioVideoBlob);
// you can even upload DataURL
recorder.getDataURL(function(dataURL) {
$.ajax({
type: 'POST',
url: '/save.php',
data: {
dataURL: dataURL
},
contentType: 'application/json; charset=utf-8',
success: function(msg) {
alert('Successfully uploaded.');
},
error: function(jqXHR, textStatus, errorMessage) {
alert('Error:' + JSON.stringify(errorMessage));
}
});
});
});
};
function uploadBlob(blob) {
var formData = new FormData();
formData.append('file', blob);
$.ajax({
url: "/save.php",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function(response) {
alert('Successfully uploaded.');
},
error: function(jqXHR, textStatus, errorMessage) {
alert('Error:' + JSON.stringify(errorMessage));
}
});
}
</script>
Here is an example save.php file that reads for video-filename and video-blob:
<?php
foreach(array('video', 'audio') as $type) {
if (isset($_FILES["${type}-blob"])) {
echo 'uploads/';
$fileName = $_POST["${type}-filename"];
$uploadDirectory = 'uploads/'.$fileName;
if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) {
echo(" problem moving uploaded file");
}
echo($fileName);
}
}
?>
Above save.php requires following FormData:
function uploadBlob(blob) {
var formData = new FormData();
formData.append('video-blob', blob);
formData.append('video-filename', 'FileName.webm');
$.ajax({
url: "/save.php",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function(response) {
alert('Successfully uploaded.');
},
error: function(jqXHR, textStatus, errorMessage) {
alert('Error:' + JSON.stringify(errorMessage));
}
});
}

Related

API Veeml to export data

I need to load data from Veeml into our SAP database.
We already scheduled some loading processes and I wonder if there is a way to query Veeml to transfer data in SAP.
You can use the API /getgrid2 to retrieve data from VEEML in a JSON format.
type: "POST",
url: « //the-url.ofyour.portal/getgrid2",
data: { "jsonstring": JSON.stringify(_jsonstring) },
success: function (data) {
console.log(data);
}
With _jsonstring as :
{
"Token": , -> authentication token
"DataView":"", -> name of the datatable
"Universe":{"column1":"''value1'"},
-> List of restriction if need (current universe)
"Chart":{
"Type":"grid",
"treillis":"",
"Dimension1":["column1 as column1"],
-> List of dimensions
"Dimension2":[],
"Fact":["AVG(Value) as Value"],
-> List of metrics
"LineorColumn":"Lines"
}
Use this endpoint to export data from VEEML.
You will get JSON that you can use in your application.
type: "POST",
data: { "jsontring": jsonstring, "DashboardId": _DashboardId},
url: "//the-url.ofyour.portal/getgrid2",
contentType: "application/json",
success: function (data) {
window.open('//xxx.datatelling.eu/nextractorcsvlink/' + data.uid, '_blank' );
}
Below is a full instance with the authentication to get the turnover by week for the year 2021 :
var _email = 'john.doe#yourcompany.com';
var _password = 'bigfan';
var _hash = CryptoJS.SHA256(_password);
var _data = {"email": _email, "password": _hash.toString()};
var _url = "https://the-url.ofyour.portal/login";
$.ajax({
type: "POST",
url: _url,
dataType : 'jsonp',
data: _data,
error: function(xhr, response, error)
{
console.log(error);
},
success: function(json)
{
console.log(json.success);
_url = "http://the-url.ofyour.portal/getgrid2";
// _jsontring is the request to pass to the API
_jsontring = {"Token": json.success,"DataView":"yourentrypointdb.dbo.
[your_dataview]","Universe":
{"Year":"'2021'"},"Chart":{"Type":"grid","treillis":"","Dimension1":["Week as Week"],
"Dimension2":[],"Fact":["SUM(Amount) as Turnover"],
"LineorColumn":"Lines"}};
_data = {"jsontring": JSON.stringify(_jsontring)};
$.ajax({
type: "POST",
url: _url,
dataType : 'jsonp',
data: _data,
error: function(xhr, response, error)
{
console.log('error');
console.log(error);
},
success: function(json)
{
console.log(json);
$("#result").html(json);
}
});
}
});

AngularJS http POST take lot of time to load data

i have a problem in loading data take from 1 to 30 seconds to load 10000 GPS coordinates ,
after checking the server side i see server take 300ms of traitement between database query and do some traitement and send response to AngularJS side
var getItineraryVehicule_n=function (id_v,date_s,date_e) {
return $q(function (resolve,reject) {
var LOCAL_TOKEN_KEY = 'yourTokenKey';
var token= window.localStorage.getItem(LOCAL_TOKEN_KEY);
token=JSON.parse(token.split('#')[0]);
$httpBackend.whenPOST(/.*/).passThrough();
$http({
method: 'post',
dataType: 'json',
url: SERVER.url+token.response.response.user.id+'/itinerary_mongodb',
header: {
'Content-Type': 'application/json'
},
data: {
"date_s": date_s ,
"date_e": date_e,
"id_v":id_v
}
}).success(function (result) {
//console.log(JSON.stringify(result));
resolve(result);
}).error(function (err) {
console.log(err);
reject('error itinerary vehicule');
});
});
}
i have just doing that but after several times of testing I see that time in the network tab is the same in the console.log time
var getItineraryVehicule_n=function (id_v,date_s,date_e) {
var d = new Date();
return $q(function (resolve,reject) {
var LOCAL_TOKEN_KEY = 'yourTokenKey';
var token= window.localStorage.getItem(LOCAL_TOKEN_KEY);
token=JSON.parse(token.split('#')[0]);
$httpBackend.whenPOST(/.*/).passThrough();
$http({
method: 'post',
dataType: 'json',
url: SERVER.url+token.response.response.user.id+'/itinerary_mongodb',
header: {
'Content-Type': 'application/json'
},
data: {
"date_s": date_s ,
"date_e": date_e,
"id_v":id_v
}
}).success(function (result) {
console.log("in the service is take : "+(new Date().getTime()-d.getTime()));
resolve(result);
}).error(function (err) {
console.log(err);
reject('error itinerary vehicule');
});
});
}

Passing $scope through AJAX, but only few variables inserted

I am trying to pass a variable through AJAX to an API. Here is the angular controller:
$scope.register = function() {
_.each($scope.photos, function(images) {
$upload.upload({
url: '/api/indorelawan/timaksibaik/register/upload-images',
method: 'POST',
data: {},
file: images
})
.success(function(data) {
$scope.team.photos.push(data.result.path);
})
});
$http({
method : 'POST',
url : '/api/indorelawan/timaksibaik/register',
data : $.param($scope.team),
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.success(function(data) {
if (!data.success) {
...
}
else {
...
}
});
}
I tried console.log the $scope.team.photos before it calls the /register API. It displays the data perfectly. But when /register API is runned, the $scope.team.photos is not included. Here is the API:
/*Register Tim Aksi Baik*/
apiRouter.post('/timaksibaik/register', function(req, res) {
// TODO: Create new value to access general statistics data, e.g.: response time.
console.log(req.body);
var team = new GoodActionTeam();
_.each(req.body, function(v, k) {
team[k] = v;
});
team.created = new Date();
team.save(function(err, data) {
if (err) {
res.status(500).json({
success: false,
message: "Gagal menyimpan data organisasi baru.",
system_error: "Error while saving organization data: " + err.message
});
}
else {
res.status(200).json({
success: true,
message: "Organisasi Berhasil Dibuat",
result: data
});
}
});
});
The output of the req.body is only:
{ logo: '/uploads/user_avatar/register/2018-1-14_18:18:3.png',
name: 'ererr',
url_string: 'ererr',
description: 'dfdfd',
focuses: [ '549789127e6a6e2c691a1fc0', '549789127e6a6e2c691a1fc0' ] }
It looks like the $scope.team.photos is not included when the data is passed to the API. What went wrong?
The $upload.upload() is async and by the time you make a post with $scope.team there is no guarantee that all the upload success callbacks have been completed

How to delete file in dropzone?

init: function() {
dzClosure = this;
document.getElementById("place-order").addEventListener("click", function(e) {
e.preventDefault();
e.stopPropagation();
dzClosure.processQueue();
});
this.on("sendingmultiple", function(data, xhr, formData) {
formData.append("key", $scope.formData.order_id);
});
this.on('success', function(file, resp) {
console.log(resp); //result - {error:false, file_id:10}
file_ids.push(resp.file_id);
});
},
removedfile: function(file) {
console.log(file_ids);
x = confirm('Do you want to delete?');
if (!x) return false;
var name = file.name;
$.ajax({
type: 'POST',
url: 'orders/fileDelete.php',
data: {"file_id": file_ids},
dataType: 'json'
});
var _ref;
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
}
Above my code working fine. But I want to delete my mysql row while clicking on the "Remove" button in dropzone. I am unable to get the current file_id in my removedfile function. Please help me and let me know how I will get resp.file_id in my removedfile function?
You could set an id property to file on success event, then on removal just get it as file.id. Hope this helps you.
init: function() {
dzClosure = this;
document.getElementById("place-order").addEventListener("click", function(e) {
e.preventDefault();
e.stopPropagation();
dzClosure.processQueue();
});
this.on("sendingmultiple", function(data, xhr, formData) {
formData.append("key", $scope.formData.order_id);
});
this.on('success', function(file, resp) {
file.id = resp.file_id;
});
},
removedfile: function(file) {
x = confirm('Do you want to delete?');
if (!x) return false;
//send delete to backend only if file was uploaded.
//Dropzone will cancel requests in progress itself.
if(file.id) {
$.ajax({
type: 'POST',
url: 'orders/fileDelete.php',
data: {"file_id": file.id},
dataType: 'json'
});
}
}
After lots of research I found where was error in my code.
Actually my ajax responded JSON. But here is dropzone.js not getting json data. So I have converted my dynamic String data to JSON format.
Code:
this.on('success', function(file, resp) {
console.log(resp); // result - {error:false, file_id:10}
var response = JSON.parse(resp);
file.file_id = response.file_id;
});

ExtJs Add Json Data

I am facing problem in ExtJs. OnClick function it should load data for one time. But it is replicating the same data on every click.
Here is my code:
function onselectionchange()
{
jQuery.ajax({
type: "POST",
url: "/Maintainer/getfolders",
data: null,
contentType: "application/json; charset=utf-8",
async: true,
success: function (result) {
var store = Ext.getCmp('gridpanel').getStore();
store.loadData(result, true);
},
error: function (p_Result) {
var error = "Error on controller: \"" + p_Controller + "\" in function: \"" + p_ControllerFunction + "\" statusText: \"" + p_Result.statusText;
alert(error);
},
traditional: true
});
}
function onselectionchange()
{
if(clickonce == "")
{
ajax({
type: "POST",
url: "/url",
data: null,
contentType: "application/json; charset=utf-8",
async: true,
success: function (result) {
enter code here
clickonce = 1;
}
});
}
else
{
alert("already selected once");
}
}
What i'am doing here is creating a global variable with clickonce. When you first click on the button the json will get uploaded and the flag on this variable will set to 1 hence it won't be populated again.

Resources