Reputation: 11
I am working on an application that records videos and saves them locally on my PC. However, I want to store these recordings directly on Google Drive instead of saving them locally. I am using Rclone to manage this process.
Here is the issue: When I stop the recording, the file is currently saved locally, but I want it to be uploaded to Google Drive. Although I have configured Rclone and written the code, I am encountering a 404 Not Found error when attempting to upload the file.
Code:
RoomClient.js
async handleLocalRecordingStop() {
console.log('MediaRecorder Blobs: ', recordedBlobs);
const dateTime = getDataTimeString();
const type = recordedBlobs[0].type.includes('mp4') ? 'mp4' : 'webm';
const blob = new Blob(recordedBlobs, { type: 'video/' + type });
const recFileName = `Rec_${dateTime}.${type}`;
const currentDevice = DetectRTC.isMobileDevice ? 'MOBILE' : 'PC';
const blobFileSize = bytesToSize(blob.size);
const recTime = document.getElementById('recordingStatus');
const recType = 'Locally';
const recordingInfo = `
<br/><br/>
<ul>
<li>Stored: ${recType}</li>
<li>Time: ${recTime.innerText}</li>
<li>File: ${recFileName}</li>
<li>Codecs: ${recCodecs}</li>
<li>Size: ${blobFileSize}</li>
</ul>
<br/>
`;
const recordingMsg = `Please wait to be processed and uploaded to your Google Drive.`;
this.saveLastRecordingInfo(recordingInfo);
this.showRecordingInfo(recType, recordingInfo, recordingMsg);
const formData = new FormData();
formData.append('file', blob, recFileName);
try {
const response = await fetch('/upload-to-drive', {
method: 'POST',
body: formData,
});
if (response.ok) {
console.log('Recording uploaded to Google Drive successfully');
} else {
console.log('Failed to upload recording file to Google Drive');
}
} catch (error) {
console.log('Error during file upload to Google Drive', error);
}
}
Server.js
const multer = require('multer');
const { exec } = require('child_process');
const fs = require('fs');
const upload = multer({ dest: 'uploads/' });
app.post('/upload-to-drive', upload.single('file'), (req, res) => {
const file = req.file;
const destination = 'singervoice:testfolder/' + file.originalname;
// Use rclone to upload to Google Drive
const command = `rclone move ${file.path} ${destination}`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`rclone error: ${error}`);
return res.status(500).send('Upload failed');
}
console.log(`rclone output: ${stdout}`);
res.send('Upload successful');
});
});
Upvotes: 1
Views: 20