cloudinary-file-upload

1.0.8 • Public • Published

Cloudinary File Upload

A simple Node.js middleware package for uploading files to Cloudinary using Multer and multer-storage-cloudinary.

Installation

Install the package and its required dependency:

npm install cloudinary-file-upload multer-storage-cloudinary

Usage

Simple Usage (Create file index.js or app.js)

const express = require('express');
const dotenv = require('dotenv');
const getUploader = require('cloudinary-file-upload');

dotenv.config();

const app = express();
const PORT = 8000;

// Set up the uploader middleware with your desired Cloudinary folder
const upload = getUploader('my-folder-name');

// File upload endpoint
app.post('/upload', upload.single('file'), (req, res) => {
  res.json({
    message: 'File uploaded successfully!',
    url: req.file.path,
  });
});

app.listen(PORT, () => {
  console.log(`Server is running on http://localhost:${PORT}`);
});

Setup (Create a .env file in your root directory:)

CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

How to Test

Using Postman or curl

  1. Start the server:
node index.js
  1. Open Postman or any API testing tool.
  2. Send a POST request to:
http://localhost:8000/upload
  1. In the Body, choose form-data.
  • Key: file (make sure type is set to File)
  • Value: Choose any image or file to upload.

Example JSON Response

{
  "message": "File uploaded successfully!",
  "url": "https://res.cloudinary.com/your_cloud_name/image/upload/v1234567890/my-folder-name/filename.jpg"
}

Author

Sanket parsewar (sanket.parsewar97@gmail.com)

Package Sidebar

Install

npm i cloudinary-file-upload

Weekly Downloads

9

Version

1.0.8

License

MIT

Unpacked Size

3.31 kB

Total Files

3

Last publish

Collaborators

  • sanketparsewar123