forked from map-of-pi/map-of-pi-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageUploader.ts
49 lines (45 loc) · 1.63 KB
/
imageUploader.ts
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
43
44
45
46
47
48
49
import cloudinary from "../utils/cloudinary";
import logger from '../config/loggingConfig';
// TODO: Is anything going to be done with this file or can it be removed?
// Seems to be redundant given the uploadImage method in image.service.ts
export const uploadMultipleImages = async (files: any) => {
try {
const uploadedImages = [];
logger.info(`Starting upload of ${files.length} images`);
for (const file of files) {
const result = await cloudinary.uploader.upload(file.path, {
folder: "uploads",
use_filename: true,
});
logger.debug(`Uploaded image: ${result.secure_url}`);
uploadedImages.push(result.secure_url);
}
logger.info(`Successfully uploaded ${uploadedImages.length} images`);
return uploadedImages;
} catch (error: any) {
logger.error('Failed to upload multiple images to Cloudinary:', {
message: error.message,
config: error.config,
stack: error.stack
});
throw new Error('Failed to upload images; please try again');
}
};
export const uploadSingleImage = async (file: any) => {
try {
logger.info(`Starting upload of single image: ${file.path}`);
const result = await cloudinary.uploader.upload(file.path, {
folder: "uploads",
use_filename: true,
});
logger.info(`Successfully uploaded single image: ${result.secure_url}`);
return result.secure_url;
} catch (error: any) {
logger.error(`Failed to upload single image to Cloudinary:`, {
message: error.message,
config: error.config,
stack: error.stack
});
throw new Error('Failed to upload single image; please try again');
}
};