Error Uploading File to Cloudinary Platform

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;

Answer №1

After some investigation, I successfully resolved the issue. It turned out that the problem did not lie with Cloudinary but rather with how the file location was being handled.

Below is the updated routes.js file:

var express = require('express');
var cloudinary = require('../cloudinary.js').cloudinary;
var router = express.Router();

router.post('/upload', function(req, res, next) {
  var fileGettingUploaded = req.files.fileToUpload.path;

  cloudinary.uploader.upload(fileGettingUploaded, function(result) {
    console.log(result);
  });
});

module.exports = router;

Answer №2

Have you attempted to specify the resource_type as video?

cloudinary.uploader.upload(req.files, 
    function(result) {console.log(result); },
    { resource_type: "video" });

If you are uploading both images and videos, you can utilize auto for the resource_type.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is the use of res.send in Express.js covered in the Node.js documentation?

http://expressjs.com/ var app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World'); }); app.listen(3000);` I was searching for information about the res.send method in the Node.js manual but couldn& ...

Update the appearance of an element in real-time using VUEJS

I am trying to use VueJS to dynamically change the position of a div. In the data function, I have a variable called x that I want to assign to the top property. However, the code I wrote doesn't seem to be working. Here is what it looks like: <tem ...

What is the best way to send an array of grouped data to a table

Here's how I organized the array: { "2023-10-01": [ { "emp_id": 1, "name": "Aruna", "code": "DO", "date": "2023-10-01" }, { &qu ...

Achieving responsive masonry layout with Bootstrap 4

I'm attempting to implement the bootstrap 4 masonry effect on my website, but I'm facing issues with card responsiveness. The page is very basic without any special effects. While the page works well when resizing the browser window, it doesn&ap ...

Development of an Angular 4 application utilizing a bespoke HTML theme

I'm in the process of creating an Angular 4 project using Angular CLI and I need to incorporate a custom HTML theme. The theme includes CSS files, JS files, and font files. Where should I place all of these files? Should they go in the asset folder? O ...

Error encountered while rendering HTML template with Django and AngularJS due to TemplateSyntaxError

Hello, I am new to Angular and Django. I have built a Django webpage and am attempting to display values from a basic AngularJS app and controller tutorial using my HTML template. However, I keep encountering an error in the index.html file when trying to ...

What is the best method to compare dates in JavaScript/JQuery to determine if one comes before the other?

I am completely new to JavaScript development and I need to accomplish the task below: I have 2 input tags containing 2 strings representing dates in the format 01/12/2014 (DAY/MONTH/YEAR). These input tags are used to search for objects with a date field ...

ng-repeat to prevent duplicate items from displaying

I intentionally have duplicates in my array of items and I am looking for a way to hide just one of them when clicked within my ng-repeat. Is there a way to hide only one of the duplicated items on click? I feel like I might be overlooking something, as ...

I'm having trouble importing sqlite3 and knex-js into my Electron React application

Whenever I try to import sqlite3 to test my database connection, I encounter an error. Upon inspecting the development tools, I came across the following error message: Uncaught ReferenceError: require is not defined at Object.path (external "path ...

Is there a way to adjust the width of a table cell in Material UI using React?

I encountered a problem where I am attempting to adjust the width of a table cell, specifically in Typescript. However, I am only able to choose between medium and small sizes for TableCellProps. Is there a workaround for this issue? I am looking to expand ...

The app.post functionality is functional, however, the app.use feature is not working as expected in my Express

After implementing the following code: app.post("/example", (req, res) => { }); everything is functioning correctly. However, when I switch to: import example from './example'; app.use("/example", example); I encounter an error: POST http ...

The conditional statement in node js is failing to execute properly

I am looking to implement a system where, after logging in, the system will check the user's role and redirect them accordingly based on their role (admin or user). The 'role' field is of integer type. Below is my code snippet: router.post( ...

Managing the callback function for multer file filtering

I have created a simple function to upload and write image files to the server using Express + Multer. Now, I am trying to handle callback errors in order to return an error message to the client like: {success:false,message:'Only images are allowed& ...

Version 1 of Vue.js is not compatible with Ajax-loaded HTML files

Currently, I am encountering a minor issue with loading content through ajax requests. I am in the process of developing a web application where everything is located on one page without any reloading. To achieve this, I have split the content into separa ...

The HTML image is not updating, the function does not appear to be triggering

My attempt to add a source to an image using JavaScript and some jQuery code I found online isn't working as expected: <html> <head> <script src = "http://www.example.com/images/"> var count=1; var initnumber=100 ...

Having trouble sending the request body via next-http-proxy-middleware

Recently, I've been attempting to develop a frontend using nextjs that communicates with a Java backend. To achieve this, I'm utilizing the npm package next-http-proxy-middleware. However, it seems like either my request body is getting lost in t ...

Angular- Product Details

I'm currently expanding my knowledge of angular (utilizing the ionic framework with phone gap included) and I'm working on developing a single application that displays a list of data. When a user clicks on an item in the list, I want to show the ...

Iterating through a JSON object using an API loop

Just starting out in JS and I am attempting to use a for loop to combine all the 'text' from various JSON objects into one cohesive paragraph. For example, it should read like this: "Hello, and welcome to the Minute Physics tutorial on basic Rock ...

Retrieve the present value from a Selectpicker using jQuery within the Codeigniter Framework

I attempted to use DOM manipulation to retrieve the value of the currently selected option from the selectpicker. My goal was to have the value of the selectpicker id="service_provider_select" printed first. However, whenever I changed the option using the ...

Steps to resolve the 'form' variable being assigned a value but never used in axios:

I am encountering an issue with a contact form that utilizes React with axios on the frontend and Express with nodemailer on the backend while running locally. The expected outcome is for me to receive an email when I click the "Submit" button. However, up ...