Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I got an error with Cloudflare R2 #188

Open
imvinojanv opened this issue Oct 1, 2024 · 1 comment
Open

I got an error with Cloudflare R2 #188

imvinojanv opened this issue Oct 1, 2024 · 1 comment

Comments

@imvinojanv
Copy link

I followed the documentation to configure with Cloudflare R2, some errors are showing on the terminal.

import { APIRoute } from "next-s3-upload";

export default APIRoute.configure({
    accessKeyId: process.env.CLOUDFLARE_R2_ACCESS_KEY_ID,
    secretAccessKey: process.env.CLOUDFLARE_R2_SECRET_ACCESS_KEY,
    bucket: process.env.CLOUDFLARE_R2_BUCKET_NAME,
    region: "ap-southeast-1",
    endpoint: "`https://${process.env.CLOUDFLARE_R2_ACCOUNT_ID}.r2.cloudflarestorage.com`"
});

ERROR:
⨯ Detected default export in 'D:\Documents\Next Projects\nextjs-s3-server-actions\app\api\cloudflare-next-s3-upload\route.ts'. Export a named export for each HTTP method instead.
⨯ No HTTP methods exported in 'D:\Documents\Next Projects\nextjs-s3-server-actions\app\api\cloudflare-next-s3-upload\route.ts'. Export a named export for each HTTP method.

Would anyone be able to fix this error?

@centsent
Copy link
Contributor

centsent commented Dec 5, 2024

You're using the App Router, but you copied the code from the doc, which defines a router for the Page Router. You can define upload router as below:

import { POST as APIRoute } from "next-s3-upload/route";

export const POST = APIRoute.configure({
	accessKeyId: process.env.S3_UPLOAD_KEY,
	secretAccessKey: process.env.S3_UPLOAD_SECRET,
	bucket: process.env.S3_UPLOAD_BUCKET,
	region: process.env.S3_UPLOAD_REGION,
	endpoint: process.env.S3_UPLOAD_ENDPOINT,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants