Spaces:
Paused
Paused
| // src/cloudinary/cloudinary.service.ts | |
| import { Injectable, Inject } from '@nestjs/common'; | |
| import { v2 as cloudinary } from 'cloudinary'; | |
| import { Readable } from 'stream'; | |
| () | |
| export class CloudinaryService { | |
| constructor(('Cloudinary') private cloudinary: any) {} | |
| async uploadImage(file: Express.Multer.File): Promise<string> { | |
| return new Promise((resolve, reject) => { | |
| const uploadStream = this.cloudinary.uploader.upload_stream( | |
| { resource_type: 'auto' }, | |
| (error, result) => { | |
| if (error) { | |
| return reject(error); | |
| } | |
| resolve(result.secure_url); | |
| }, | |
| ); | |
| const stream = new Readable(); | |
| stream.push(file.buffer); | |
| stream.push(null); | |
| stream.pipe(uploadStream); | |
| }); | |
| } | |
| } | |