-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudinary.js
More file actions
42 lines (34 loc) · 1.1 KB
/
cloudinary.js
File metadata and controls
42 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { v2 as cloudinary } from 'cloudinary';
(async function() {
// Configuration
cloudinary.config({
cloud_name: 'ddyembipe',
api_key: '372393232723255',
api_secret: '<your_api_secret>' // Click 'View API Keys' above to copy your API secret
});
// Upload an image
const uploadResult = await cloudinary.uploader
.upload(
'https://res.cloudinary.com/demo/image/upload/getting-started/shoes.jpg', {
public_id: 'shoes',
}
)
.catch((error) => {
console.log(error);
});
console.log(uploadResult);
// Optimize delivery by resizing and applying auto-format and auto-quality
const optimizeUrl = cloudinary.url('shoes', {
fetch_format: 'auto',
quality: 'auto'
});
console.log(optimizeUrl);
// Transform the image: auto-crop to square aspect_ratio
const autoCropUrl = cloudinary.url('shoes', {
crop: 'auto',
gravity: 'auto',
width: 500,
height: 500,
});
console.log(autoCropUrl);
})();