txb-cloudinary-image-uploader 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +9 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "txb-cloudinary-image-uploader",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A lightweight, promise-based utility to handle seamless image uploads to Cloudinary directly from the browser.",
5
5
  "license": "ISC",
6
6
  "author": "Saleh Ahmed Mahin",
package/readme.md CHANGED
@@ -1,63 +1,22 @@
1
1
  # Cloudinary Image Upload Utility
2
2
 
3
- A lightweight TypeScript utility function to handle image uploads directly from the client-side (browser) to Cloudinary using **Unsigned Uploads**. This utility uses the native `fetch` API, eliminating the need for heavy external libraries like Axios.
3
+ A lightweight, type-safe TypeScript utility for handling direct client-side image uploads to Cloudinary using **Unsigned Uploads**. This implementation leverages the native `fetch` API, keeping your bundle size small by avoiding external dependencies like Axios.
4
4
 
5
5
  ## Table of Contents
6
6
  * [Features](#features)
7
7
  * [Prerequisites](#prerequisites)
8
- * [Installation](#installation)
9
- * [Usage](#usage)
8
+ * [The Utility Function](#the-utility-function)
9
+ * [Usage Example (React)](#usage-example-react)
10
10
  * [Response Structure](#response-structure)
11
11
 
12
12
  ## Features
13
- - **Simple Integration**: Upload images with a single function call.
14
- - **TypeScript Support**: Fully typed interface for predictable data structures and better DX.
15
- - **Detailed Error Handling**: Log detailed error data to the console if the upload fails.
16
- - **Lightweight**: Built with the native Fetch API—no extra dependencies required.
13
+ - **Zero Dependencies**: Uses the native Fetch API.
14
+ - **Type Safety**: Fully typed interface for predictable data structures and better DX.
15
+ - **Error Handling**: Captures and logs detailed Cloudinary API responses.
16
+ - **Lightweight**: Optimized for modern browser environments.
17
17
 
18
18
  ## Prerequisites
19
- Before using this function, gather the following details from your Cloudinary Dashboard:
19
+ Before using this function, gather the following details from your [Cloudinary Dashboard](https://cloudinary.com/console):
20
20
  1. **Cloud Name**: Your unique Cloudinary identifier.
21
21
  2. **Upload Preset**: Create an **'Unsigned'** upload preset in Cloudinary Settings (Settings > Upload).
22
- 3. **Cloudinary URL**: Typically formatted as: `https://api.cloudinary.com/v1_1/YOUR_CLOUD_NAME`
23
-
24
- ## Installation
25
- Create a file named `cloudinary.ts` inside your project's `utils` or `lib` folder and paste the function code there.
26
-
27
- ```bash
28
- # No additional packages are required.
29
-
30
- ### React Example
31
- ```
32
- import { uploadToCloudinary } from './utils/cloudinary';
33
-
34
- const ImageUploadComponent = () => {
35
- const handleFileChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
36
- const file = event.target.files?.[0];
37
- if (!file) return;
38
-
39
- // Use environment variables for production security
40
- const CLOUDINARY_URL = "[https://api.cloudinary.com/v1_1/your_cloud_name](https://api.cloudinary.com/v1_1/your_cloud_name)";
41
- const UPLOAD_PRESET = "your_unsigned_preset";
42
-
43
- try {
44
- const response = await uploadToCloudinary(file, UPLOAD_PRESET, CLOUDINARY_URL);
45
-
46
- console.log("Uploaded URL:", response.url);
47
- console.log("Public ID:", response.public_id);
48
-
49
- alert("Upload Successful!");
50
- } catch (error) {
51
- console.error("Upload failed:", error);
52
- alert("Failed to upload image. Please check the console for details.");
53
- }
54
- };
55
-
56
- return (
57
- <div>
58
- <label>Choose an image:</label>
59
- <input type="file" onChange={handleFileChange} />
60
- </div>
61
- );
62
- };
63
- ```
22
+ 3. **API URL**: Typically formatted as: `https://api.cloudinary.com/v1_1/YOUR_CLOUD_NAME/image/upload`