muaz-khan / RTCMultiConnection-Server

RTCMultiConnection socket.io server (npm install rtcmulticonnection-server)
https://muazkhan.com:9001/
MIT License
274 stars 146 forks source link

RecordRTC Upload to PHP #31

Open rayj00 opened 3 years ago

rayj00 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

I do not know java. Sorry.

From: vcluo @. Sent: Tuesday, May 11, 2021 11:50 PM To: muaz-khan/RTCMultiConnection-Server @.> Cc: rayj00 @.>; Author @.> Subject: Re: [muaz-khan/RTCMultiConnection-Server] RecordRTC Upload to PHP (#31)

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; }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/muaz-khan/RTCMultiConnection-Server/issues/31#issuecomment-839411280 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSNU47HHXQVQGRI5QPIC2LTNH3HHANCNFSM4YWAQC7A . https://github.com/notifications/beacon/ABSNU43NX2CBGAZM2I6XHZTTNH3HHA5CNFSM4YWAQC7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGIEGMUA.gif