-
Notifications
You must be signed in to change notification settings - Fork 78
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
Custom Path for File Uploads with App Router #176
Comments
Update By using the import { POST as route } from "next-s3-upload/route";
export const POST = route.configure({
async key(req, filename) {
console.log('KEY CHANGED');
return `${'myfiles'}/${filename}`;
},
}); However, upon further testing, I encountered difficulties accessing the body of the import { POST as route } from "next-s3-upload/route";
export const POST = route.configure({
async key(req, filename) {
try {
const body = await req.json();
const folderName = body.folderName;
return `${folderName}/${filename}`;
} catch (error) {
console.error("Error parsing JSON body:", error);
return `${filename}`;
}
},
}); Additionally, attempting to access the body directly using This further complicates the process of dynamically setting the file path. |
I had the same issue. The request object is not usable in this context.
It now works as expected. |
I cant seem to get body or headers to work but what i did to simplify things is use the url
|
I am encountering difficulties specifying a custom path for file uploads when using the 'next-s3-upload' library within a Next.js application, specifically with the App Router. The library provides an example for configuring the API route with a custom key function, but it seems that this configuration may not be fully compatible with the App Router.
Documentation Reference:
The relevant documentation snippet is as follows:
Issue Details:
Expected Behavior: I expect to be able to specify a custom path for file uploads using the library when using the App Router.
Actual Behavior: When using the provided configuration with App Router, I encounter errors such as 'TypeError: Body is unusable' or 'TypeError: s.status is not a function'.
Additional Information:
The configuration appears to be designed for the Pages Router, and it may not work seamlessly with the App Router in Next.js.
It seems that there might be a need for additional documentation or clarification on how to configure the library for the App Router in Next.js.
The text was updated successfully, but these errors were encountered: