expressjs / multer

Node.js middleware for handling `multipart/form-data`.
MIT License
11.57k stars 1.06k forks source link

MulterError : Unexpected field #908

Closed funcoder001 closed 4 years ago

funcoder001 commented 4 years ago

const express = require('express') const cors = require('cors') const uuid = require('uuid') const youtube = require('youtube-api') const open = require('open') const multer = require('multer') const app = express() const fs = require('fs') const credentials = require('./credentials.json') app.use(express.json()) app.use(cors()) 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('/upload', uploadVideoFile, (req, res) => { if(req.file){ const filename= req.file.filename; const {title, description} = req.body;

    open(oAuth.generateAuthUrl({
        access_type: 'offline',
        scope: 'https://www/googleapis.com/auth/youtube.upload',
        state: JSON.stringify({
            filename, title, description
        })  
    }))
}

}) app.get('/oauth2callback', (req, res) => { res.redirect('http://localhost:5000/success') const {filename, title, description} = JSON.parse(req.query.state)

oAuth.getToken(req.query.code, (err, token) => {
    if (err) {

        return
    }
    oAuth.setCredentials(tokens)
    youtube.video.insert({
        resource: {
            snippet: { title, description },
            status: {privacyStatus: 'private'},

        },
        part: 'snippet,status',
        media: {
            body: fs.createReadStream(filename)
        }
    }, (err, data) => {
        console.log("Done")
        process.exit()
    })
})

}) const oAuth = youtube.authenticate({ type: 'oauth', client_id: credentials.web.client_id, client_secret: credentials.web.client_secret, redirect_url: credentials.web.redirect_uris[0]

}) const PORT = 3000 app.listen(PORT)`

It keeps on giving me this when I try to make a request to my server from my react app,

MulterError: Unexpected field at wrappedFileFilter (C:\Users\Rushil Murikinati\Desktop\React App\main-backend\node_modules\multer\index.js:40:19) at Busboy. (C:\Users\Rushil Murikinati\Desktop\React App\main-backend\node_modules\multer\lib\make-middleware.js:114:7) at Busboy.emit (events.js:310:20) at Busboy.emit (C:\Users\Rushil Murikinati\Desktop\React App\main-backend\node_modules\busboy\lib\main.js:38:33) at PartStream. (C:\Users\Rushil Murikinati\Desktop\React App\main-backend\node_modules\busboy\lib\types\multipart.js:213:13) at PartStream.emit (events.js:310:20) at HeaderParser. (C:\Users\Rushil Murikinati\Desktop\React App\main-backend\node_modules\dicer\lib\Dicer.js:51:16) at HeaderParser.emit (events.js:310:20) at HeaderParser._finish (C:\Users\Rushil Murikinati\Desktop\React App\main-backend\node_modules\dicer\lib\HeaderParser.js:68:8) at SBMH. (C:\Users\Rushil Murikinati\Desktop\React App\main-backend\node_modules\dicer\lib\HeaderParser.js:40:12)

ghinks commented 4 years ago

hello @funcoder001 could you provide a small working example of this issue if it is still a problem for you. The express team get many issues raised and without working demonstrable examples it is tough for us to address them.

ghinks commented 4 years ago

I am closing this issue as we have asked for a working example of the issue. I will gladly re-open the issue if you provide one.