import S3 from "aws-sdk/clients/s3" ; import { NextApiHandler } from "next" ; import { generate as generateId } from "shortid" ; const s3 = new S3 ( { credentials : { accessKeyId : process . env . AWS_S3_ACCESS_KEY_ID , secretAccessKey : process . env . AWS_S3_SECRET_ACCESS_KEY , } , } ) ; const handler = async ( req , res ) => { const snapshotId = generateId ( ) ; const contents = req . body as { id : string ; innerText : string ; } [ ] ; try { await s3 . upload ( { Bucket : process . env . AWS_S3_BUCKET , Key : `${ snapshotId }.json` , Body : JSON . stringify ( contents ) , } ) . promise ( ) ; } catch ( err ) { console . error ( err ) ; res . status ( 500 ) . send ( "Internal Server Error" ) ; return res . end ( ) ; } res . status ( 200 ) ; res . json ( { snapshotId } ) ; res . end ( ) ; } ; export const config = { api : { bodyParser : { sizeLimit : "256kb" } , } , } ; export default handler ;