Answer the question
In order to leave comments, you need to log in
How to properly return cropped images from Cloudinary?
Hello, I am uploading an avatar to cloudinary. How to correctly crop the output image and get a link to the resized image?
Is it right to do it this way?
export const uploadFromBuffer = (buffer: Buffer, folder: string) => {
return new Promise((resolve, reject) => {
const stream = cloudinary.uploader.upload_stream(
{
folder,
},
(error: UploadApiErrorResponse | undefined, result: UploadApiResponse | undefined): void => {
console.log(error, result)
if (result) {
let cropedImg = result.url
cropedImg = cropedImg.replace('upload', 'upload/g_face,h_200,w_200,c_thumb')
resolve({
url: cropedImg,
size: Math.round(result.bytes / 1024),
height: result.height,
width: result.width,
})
} else {
reject(error)
}
}
)
streamifier.createReadStream(buffer).pipe(stream)
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question