I am currently developing a REST API using Express.js. The main functionality of the API involves accepting a video file from the client and uploading it to Cloudinary. Interestingly, when I test the API by returning the file back to the client, everything works perfectly fine. However, as soon as I try to upload the same file to Cloudinary, an error occurs with the message:
"file.match is not a function"
I am unsure about what exactly "file.match" is and why it's causing this issue. Has anyone else encountered this problem before, and if so, how did you go about solving it? Below is the specific code that seems to be causing the problem:
app.js
var express = require('express');
var formidable = require('express-formidable');
var app = express();
app.use(formidable());
var routes = require('./routes');
app.use('/routes', routes);
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log('Express server is listening on port ' + port);
});
routes.js
var express = require('express');
var cloudinary = require('../cloudinary.js').cloudinary;
var router = express.Router();
router.post('/upload', function(req, res, next) {
cloudinary.uploader.upload(req.files, function(result) {
console.log(result);
});
});
module.exports = router;
cloudinary.js
var cloudinary = require('cloudinary');
cloudinary.config({
cloud_name: 'name',
api_key: 'key',
api_secret: 'secret'
});
module.exports.cloudinary = cloudinary;