Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecordRTC Upload to PHP #31

Open
rayj00 opened this issue Mar 5, 2021 · 2 comments
Open

RecordRTC Upload to PHP #31

rayj00 opened this issue Mar 5, 2021 · 2 comments

Comments

@rayj00
Copy link

rayj00 commented Mar 5, 2021

No matter what php and javascript I use, nothing seems to work? I cannot upload the webm to the server?

save.php

`<?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);
}

}
?>

JavaScript code
var fileType = 'video'; // or "audio"
var fileName = 'ABCDEF.webm'; // or "wav"

var formData = new FormData();
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', blob);

xhr('save.php', formData, function (fName) {
window.open(location.href + fName);
});

function xhr(url, data, callback) {
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
callback(location.href + request.responseText);
}
};
request.open('POST', url);
request.send(data);
}`

And my dev console has this:
RecordRTC version: 5.5.9
17:38:51.966 RecordRTC.js:63 started recording video stream.
17:38:51.967 RecordRTC.js:1057 Using recorderType: MediaStreamRecorder
17:38:51.968 RecordRTC.js:2104 Passing following config over MediaRecorder API. {type: "video", mimeType: "video/webm", checkForInactiveTracks: false, initCallback: ƒ}
17:38:51.969 RecordRTC.js:713 Recorder state changed: recording
17:38:51.969 RecordRTC.js:103 Initialized recorderType: MediaStreamRecorder for output-type: video
17:38:53.519 RecordRTC.js:129 Stopped recording video stream.
17:38:53.520 RecordRTC.js:713 Recorder state changed: stopped
17:38:53.522 RecordRTC.js:170 video/x-matroska;codecs=avc1,opus -> 121 KB
17:38:53.523 (index):347 POST url = save.php
17:38:53.696 (index):348 XHR finished loading: POST "https://bcast.mydomain.us/save.php".
xhr @ (index):348
(anonymous) @ (index):335
_callback @ RecordRTC.js:181
mediaRecorder.ondataavailable @ RecordRTC.js:2184

I get nothing in the uploads folder.

ideas?

@vcluo
Copy link

vcluo commented May 12, 2021

hello i use java to file upload holp can help you

@ResponseBody
@RequestMapping("upload")
public JSONObject add(HttpServletRequest request,HttpServletResponse response) 
		throws IllegalStateException, IOException, ServletException {

// response.setHeader("Access-Control-Allow-Origin","*");
// response.setHeader("Access-Control-Allow-Methods","GET,POST");
JSONObject jsonObject = new JSONObject();
Collection parts = request.getParts();
String stateString = "null or error input data";
for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
Part part = iterator.next();
String partname = part.getName();
// String headNames = part.getHeader("data");
// String submitname = part.getSubmittedFileName();
if (partname.equals("data")) {
FileUtil.getFile(part.getInputStream(), "C:\rtcuploader\"+Math.round(Math.random() * 100000000)+
new SimpleDateFormat("yyyyMMdd").format(new Date()).concat(".webm"));
stateString = "success";
}
}
jsonObject.put("status", stateString);
return jsonObject;
}

@rayj00
Copy link
Author

rayj00 commented May 12, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants