payload-cloudinary
Version:
A Cloudinary storage plugin for Payload CMS
50 lines • 1.79 kB
TypeScript
import type { v2 as cloudinaryType } from 'cloudinary';
import type { CloudinaryStorageOptions, GenerateClientUploadSignatureParams, ClientUploadSignatureResponse } from './types';
/**
* Creates a server handler for generating Cloudinary upload signatures
*
* This should be used to create an API endpoint that your client-side code
* can call to get a signature for uploading to Cloudinary.
*
* @example
* ```ts
* // In your API route (e.g., app/api/cloudinary/upload/route.ts for Next.js)
* import { NextRequest, NextResponse } from 'next/server'
* import { createCloudinaryServerHandler } from 'payload-cloudinary'
* import { v2 as cloudinary } from 'cloudinary'
*
* // Configure cloudinary
* cloudinary.config({
* cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
* api_key: process.env.CLOUDINARY_API_KEY,
* api_secret: process.env.CLOUDINARY_API_SECRET,
* })
*
* const handler = createCloudinaryServerHandler({
* cloudinary,
* folder: 'payload-media',
* versioning: { enabled: false },
* publicID: { enabled: true },
* })
*
* export async function POST(req: NextRequest) {
* try {
* const body = await req.json()
* const signature = await handler(body)
* return NextResponse.json(signature)
* } catch (error) {
* return NextResponse.json(
* { error: 'Failed to generate signature' },
* { status: 500 }
* )
* }
* }
* ```
*/
export declare function createCloudinaryServerHandler(options: {
cloudinary: typeof cloudinaryType;
folder?: string;
versioning?: CloudinaryStorageOptions['versioning'];
publicID?: CloudinaryStorageOptions['publicID'];
}): (params: GenerateClientUploadSignatureParams) => Promise<ClientUploadSignatureResponse>;
//# sourceMappingURL=createServerHandler.d.ts.map