-
-
Notifications
You must be signed in to change notification settings - Fork 187
feat: S3 file upload #427
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
base: main
Are you sure you want to change the base?
feat: S3 file upload #427
Conversation
Co-authored-by: Jean <jean@analoginterface.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
JeanMeijer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it now
apps/web/src/app/api/upload/route.ts
Outdated
| // Configure the upload router with S3 | ||
| // The aws() client automatically reads from environment variables: | ||
| // - AWS_ACCESS_KEY_ID | ||
| // - AWS_SECRET_ACCESS_KEY | ||
| // - AWS_REGION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove all the comments, except for: // 100MB in bytes
apps/web/src/app/api/upload/route.ts
Outdated
| export async function POST(request: Request) { | ||
| // Get the session from better-auth | ||
| const headersList = await headers(); | ||
| const session = await auth.api.getSession({ | ||
| headers: headersList, | ||
| }); | ||
|
|
||
| // Check if user is authenticated | ||
| if (!session?.user) { | ||
| return new Response( | ||
| JSON.stringify({ | ||
| error: "Unauthorized", | ||
| message: "You must be logged in to upload files", | ||
| }), | ||
| { | ||
| status: 401, | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| }, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| // User is authenticated, proceed with upload | ||
| return uploadPOST(request); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead use:
import { RejectUpload, route, type Router } from '@better-upload/server';
import { aws } from '@better-upload/server/clients';
const auth = (req: Request) => ({ id: 'fake-user-id' });
const router: Router = {
client: aws(),
bucketName: 'my-bucket',
routes: {
images: route({
fileTypes: ['image/*'],
multipleFiles: true,
maxFiles: 4,
onBeforeUpload: async ({ req, files, clientMetadata }) => {
const user = await auth(req);
if (!user) {
throw new RejectUpload('Not logged in!');
}
},
}),
},
};
package.json
Outdated
| ], | ||
| "dependencies": { | ||
| "@better-upload/client": "^3.0.2", | ||
| "@better-upload/server": "^3.0.2" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you fucking retarded, install it in apps/web
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 5 files
|
@tembo fix it based on the review and run format |
Done! I've addressed all the feedback:
|
Description
Implements server-side file upload to AWS S3 using
better-uploadwithbetter-authintegration. Supports up to 10 files, 100MB each, any content type.Screenshots / Recordings
Type of Change
Related Areas
Testing
Checklist
Notes
Added
/api/uploadroute, configuredbetter-uploadfor S3, and enforced authentication. Updated.env.exampleandenv/server.tsfor AWS S3 credentials. Addedbetter-uploaddependencies.By submitting, I confirm I understand and stand behind this code. If AI was used, I’ve reviewed and verified everything myself.
Summary by cubic
Adds an authenticated server-side S3 upload endpoint at /api/upload using better-upload. Supports up to 10 files (100MB each) with any content type.
New Features
Migration
Written for commit f1fbee7. Summary will update automatically on new commits.