I'm attempting to pass a video file from my front end (using React and Axios) and upload it to youtube from my backend using express (using this tutorial https://youtu.be/xhiWEpU-h-A). The file gets submitted in the form of a 'formdata' object from my front end.
Here's my backend
const oAuth = youtube.authenticate({type: 'oauth',client_id: credentials.web.client_id,client_secret: credentials.web.client_secret,//Redirect uris has not been set up, may cause errorsredirect_url: credentials.web.redirect_uris[0]})const storage = multer.diskStorage({destination: '/',filename(req, file, cb) {const newFileName = ${uuid()}-${file.originalname}cb(null,newFileName);}})const uploadVideoFile = multer({storage: storage}).single("videoFile");app.post('/api/uploadVideo', uploadVideoFile, (req, res)=>{console.log("upload video endpoint established")console.log(file was set to: ${req.file})if(req.file)console.log('we found a file')elseconsole.log('no file?')console.log(title: ${title} description: ${description})return;//ignore the stuff below here
Here's the function that submits the formdata on the front end, as well as the state variables
const uploadVideo = ()=>{//uploadVideo(Credentials, [{}]) const videoData = new FormData() videoData.append("videoFile", videoFile) videoData.append("title", videoTitle) videoData.append("description", videoDescription) console.log(videoData) Axios.post("http://localhost:3001/api/uploadVideo", videoData).then((response) =>{ console.log(response.data) })} const [videoTitle, setVideoTitle] = useState('')const [videoMode, setVideoMode] = useState(true)const [videoFile, setVideoFile] = useState(null)`
And here's the form object that accepts the video file
<Form.Control type="file" accept="video/mp4" disabled={!videoMode} onChange={(e)=>{setVideoFile(e.target.files[0])}}></Form.Control>`
When I attempt to run the function I get the following error message on my server
Error: EPERM: operation not permitted, open 'C:\fb434fe2-e46c-4d8c-8f41-7b807f1b92a7-Column test - Google Chrome 2022-01-12 17-27-21.mp4'
the error occurs before the post request can be resolved
I was hoping multer would be able to locate the file I passed to it but I simply get a permission error.