Skip to main content
Home

A simple Node.js utility for uploading images to Cloudinary by handling the API interactions. Just provide the Cloudinary URL, upload preset, API key, and local file path to get the secure URL of the uploaded image.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (0.1.2)

Cloudinary Image Upload Utility

A simple utility package to upload images to Cloudinary using Node.js.

Installation

To install the package, use npm or yarn:

npx jsr add @jmacera/cloudinary-image-upload

Usage

Import the handleFileChange function from the package and use it to upload an image to Cloudinary.

Example

import { handleFileChange } from 'your-package-name';

async function uploadImage(file: File) {
  const cloudinaryUrl = 'https://api.cloudinary.com/v1_1/your-cloud-name/image/upload';
  const uploadPreset = 'your-upload-preset';
  const apiKey = 'your-api-key';

  try {
    const secureUrl = await handleFileChange(cloudinaryUrl, uploadPreset, apiKey, file);
    console.log('Uploaded Image URL:', secureUrl);
  } catch (error) {
    console.error('Error uploading image:', error);
  }
}

uploadImage();

Parameters

  • cloudinaryUrl: string - The Cloudinary API URL for uploading images.
  • uploadPreset: string - The upload preset configured in your Cloudinary account.
  • apiKey: string - Your Cloudinary API key.
  • file: File - The file you want to upload.

Return Value

The function returns a

  • Promise<string | undefined>:string: The secure URL of the uploaded image if successful.
  • undefined: If an error occurs during the upload.

Requirements

Node.js v16.0.0 or later. A Cloudinary account with an API key and an upload preset.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

If you want to contribute to this package, feel free to submit issues or pull requests on the GitHub repository.

Author

John Micheal Acera - https://github.com/johnmichealacera

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@jmacera/cloudinary-image-upload

Import symbol

import * as cloudinary_image_upload from "@jmacera/cloudinary-image-upload";
or

Import directly with a jsr specifier

import * as cloudinary_image_upload from "jsr:@jmacera/cloudinary-image-upload";

Add Package

pnpm i jsr:@jmacera/cloudinary-image-upload
or (using pnpm 10.8 or older)
pnpm dlx jsr add @jmacera/cloudinary-image-upload

Import symbol

import * as cloudinary_image_upload from "@jmacera/cloudinary-image-upload";

Add Package

yarn add jsr:@jmacera/cloudinary-image-upload
or (using Yarn 4.8 or older)
yarn dlx jsr add @jmacera/cloudinary-image-upload

Import symbol

import * as cloudinary_image_upload from "@jmacera/cloudinary-image-upload";

Add Package

vlt install jsr:@jmacera/cloudinary-image-upload

Import symbol

import * as cloudinary_image_upload from "@jmacera/cloudinary-image-upload";

Add Package

npx jsr add @jmacera/cloudinary-image-upload

Import symbol

import * as cloudinary_image_upload from "@jmacera/cloudinary-image-upload";

Add Package

bunx jsr add @jmacera/cloudinary-image-upload

Import symbol

import * as cloudinary_image_upload from "@jmacera/cloudinary-image-upload";