Adding a 2nd email and a link

This script (code below) successfully records a webcam.
After recording, when 'upload" is selected:

  1. the recorded file is directed (by a php file) to upload to a /Folder destination.
  2. and the the User is directed to a Form page (to complete - requiring the Users’ email address).

When the User completes the Form, and selects “send”, I receive the Form contents (via email).

How can I receive a copy of the recorded file, with the Form contents, via email?
How can the User receive a copy of the recorded file, to the email address he entered into the Form?

Any ideas/suggestions will be appreciated.

 <script>
            const video = document.querySelector('video')
            const startvideo = document.querySelector('.start')
            const upload = document.querySelector('.upload')
            const initRecorder = stream => {
            let blob
              video.srcObject = stream
              startvideo.removeAttribute('disabled')
              video.addEventListener('loadedmetadata', () => {
              video.play()
              })
              recorder.addEventListener('dataavailable', ({ data }) => {
              video.srcObject = null
              video.src = URL.createObjectURL(data)
              // Create a blob from the data for upload
              blob = new Blob([data], { type: 'video/webm' })
              })

              startvideo.addEventListener('click', () => {
              stopvideo.removeAttribute('disabled')

              show()
              reset()
              start()
              recorder.start()
		 				  // Get the video element with id="myVideo"
							document.getElementsByTagName("span")[0].removeAttribute("class")
							document.getElementsByTagName("span")[0].setAttribute("class", "colorred")
		        	//document.getElementById("demo").innerHTML ="Recording...."
							})

							stopvideo.addEventListener('click', () => {
              upload.removeAttribute('disabled')
              recorder.stop()
              stop()
							document.getElementsByTagName("span")[0].removeAttribute("class")
							document.getElementsByTagName("span")[0].setAttribute("class", "colorgreen")
							//document.getElementById("demo").innerHTML ="recorded Successfully ..."
              video.setAttribute("controls","controls")
							})

							// Upload the video blob as form data ............................
              upload.addEventListener('click', () => {
              uploadBlob(blob)
            })
          }

           ///////////////////////////////////////////////////

		  		  //Reset the Camera
		  		             function resetCamera(){
		  		                location.reload();
		  		              }

/////////////////////////////////////////////////////////

					  //   uploading functionality

            	var blob, fileName, fileObject;
              function uploadBlob(blob) {
                  prepareBlob(blob);
            			InitUploading();
              }
            //////////////////////////////////preparing blob metadat////////////////////
            function prepareBlob(blob){
            	    	// generating a random file name
            			 fileName = getFileName('webm');
            			 // we need to upload "File" --- not "Blob"
            			 fileObject = new File([blob], fileName, {
            			 type: 'video/webm'
            		 });
            }
            function InitUploading()
            			 {
            					 uploadToPHPServer(fileObject, function (response, fileDownloadURL) {
            							 if (response !== 'ended') {
            									 document.getElementById('header').innerHTML = response; // upload progress
            									 return;
            							 }
            							 document.getElementById('header').innerHTML = '<a href="' + fileDownloadURL +
            									 '" target="_blank">' +
            									 fileDownloadURL + '</a>';
            							 //alert('Successfully uploaded recorded blob.');
            							 // preview uploaded file
            							 video.src = fileDownloadURL;
            							 // open uploaded file in a new tab
            							 window.open(fileDownloadURL);
            					 });
            			 }

              ///////////////////////////////////////////////////////////////////////////////////

                    function makeXMLHttpRequest(url, data, callback) {
                        var request = new XMLHttpRequest();
                        request.onreadystatechange = function () {
                            if (request.readyState == 4 && request.status == 200) {
                                if (request.responseText === 'success') {
                                    callback('Upload Complete');
                                    return;
                                }
                                //alert(request.responseText);

								window.location.href = '../uploadWC.html';

                    return;

                            }
                        };
                        request.upload.onloadstart = function () {
                            callback('Upload Begins...');
                        };
                        request.upload.onprogress = function (event) {
                            callback('Upload Progress ' + Math.round(event.loaded / event.total * 100) + "%");
                        };
                        request.upload.onload = function () {
                            callback('Progress Ending');
                        };
                        request.upload.onload = function () {
                            callback('Upload Complete');
                        };
                        request.upload.onerror = function (error) {
                            callback('Upload Failed.');
                        };
                        request.upload.onabort = function (error) {
                            callback('Upload Aborted.');
                        };
                        request.open('POST', url);
                        request.send(data);
                    }
                    // this function is used to generate random file name
                    function getFileName(fileExtension) {
                        var d = new Date();
                        var year = d.getUTCFullYear();
                        var month = d.getUTCMonth() +1;
                        var date = d.getUTCDate();
                        return 'VTH-' + year + month + date + '-' + getRandomString() + '.' + fileExtension;
                    }

                    function getRandomString() {
                        if (window.crypto && window.crypto.getRandomValues && navigator.userAgent.indexOf('Safari') === -1) {
                            var a = window.crypto.getRandomValues(new Uint32Array(3)),
                                token = '';
                            for (var i = 0, l = a.length; i < l; i++) {
                                token += a[i].toString(36);
                            }
                            return token;
                        } else {
                            return (Math.random() * new Date().getTime()).toString(36).replace(/\./g, '');
                        }

					}
					}
}

              navigator
                .mediaDevices
                .getUserMedia({audio: true, video: true })
                .then(initRecorder)
                .catch(console.error)

         </script>

Rethink your question. The script uploads a file to the server. We’re talking video, not a few text characters.

How can I receive a LINK to the recorded file, with form contents, via email?
How can the User receive a LINK to the recorded file, to the email address he entered into the Form?

That simple change, will simplify your tasks greatly.

Thank you for your reply. Yes, that would simplify things. How could each file be stored in a unique location, (for a unique link) so that one person couldn’t see or download another persons video file? The script generates a random file name, if someone knew the folder name, it would still be tough to figure out what the file names are in the folder, correct?

I believe a way to do it would be to store the video files in an area that your web server does not expose, so they cannot be accessed directly via a web browser. When you want to view them, your PHP code validates the user credentials and then delivers the file to the browser. I can picture how that works with a file download, though I’m not experienced in streaming but presume a similar method could be used.

Random file names are all fine, but users can still stumble on things if you place them somewhere they can access directly. “Security through obscurity” is not the best solution.

As it’s the server-side code that will be controlling where the file is stored, and how the emails are sent, it’s hard to advise on where that would be modified without seeing it. I can’t see that you’d need to change the client-side JavaScript.

Thanks for your reply. Here’s more info:
The script sends the file to the storage folder, via this file code:

<?php

foreach(array('video', 'audio') as $type) {

if (isset($_FILES["${type}-blob"])) {

$fileName = $_POST["${type}-filename"];

$uploadDirectory = 'uploadWC/'.$fileName;

if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) {

echo(" problem moving uploaded file");

}
echo($fileName);
}
}
?>

And after the User selects (file) “upload”, the User is directed to a page with a Form, and this file sends the Form:

<?php
//check if form was sent
if($_POST){
	$to = 'WCform@....com';
	$subject = 'WebCamForm';

	$name = $_POST['name'];
	$email = $_POST['email'];
	$message = $_POST['message'];
	$headers = $name;
	$message .= "\r\n\r\n" . $name;

if( empty($_POST["some_place"]) or $_POST['some_place'] != "glory" )
{
   header("HTTP/1.0 403 Forbidden");
   	}else{
   		mail( $to, $subject, $message, $email, $headers );
   	}
		header('Location: http://www....com/ThankYou.html');
   exit;
}
?>

I don’t know how to add code each time to automatically add the User’s Form-entered email address and file name link, to the emailing. Any help will be appreciated.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.