Answers for "how to upload document cloddinary"

0

how to upload document cloddinary

// util.cloud.ts
import { v2 as cloudinary } from 'cloudinary'

export const cloudStorage = (filename: string): Promise<Record<string, any>> => {
	return new Promise((resolve, reject) => {
		cloudinary.config({
			cloud_name: process.env.CLOUDINARY_NAME,
			api_key: process.env.CLOUDINARY_API_KEY,
			api_secret: process.env.CLOUDINARY_API_SECRET,
			shorten: true,
			secure: true,
			ssl_detected: true
		})

		cloudinary.uploader
			.upload(filename, { resource_type: 'auto' })
			.then((response: UploadApiResponse) => resolve(response))
			.catch((error) => reject(error))
	})
}

// upload.ts
const urls = []
	const image = req.files.image
	const document = req.files.document
	const files = image.concat(document)

	for (let file of files) {
		try {
			const response = await cloudStorage(file.path)
			urls.push(response)
		} catch (err) {
			console.log(err)
		}
	}
Posted by: Guest on February-25-2021
0

how to upload document cloddinary

resource_type = auto
please check more about options this -> https://cloudinary.com/documentation/image_upload_api_reference
Posted by: Guest on February-25-2021

Code answers related to "how to upload document cloddinary"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language