Skip to content

Feat/98 file upload api#222

Open
manvinderjit wants to merge 21 commits into
devfrom
feat/98-file-upload-api
Open

Feat/98 file upload api#222
manvinderjit wants to merge 21 commits into
devfrom
feat/98-file-upload-api

Conversation

@manvinderjit

@manvinderjit manvinderjit commented Aug 6, 2025

Copy link
Copy Markdown
Collaborator

Summary

Add file upload api for uploading files to R2 buckets.

Tests

WIP - Pending

Additional information

Closes #98

@github-actions github-actions Bot added the Backend/API 🍑 Anything related to the backend or API side of things label Aug 6, 2025
@manvinderjit manvinderjit changed the title Feat/98 file upload api WIP - Feat/98 file upload api Aug 6, 2025
add migration schema for the uploads table to store files.
add table to DBTables constant.
add uploadFile method to save file data.
update the api to save the data and leverage validation functions.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 10, 2025

Copy link
Copy Markdown

Deploying volunteer with  Cloudflare Pages  Cloudflare Pages

Latest commit: ea9a9f6
Status: ✅  Deploy successful!
Preview URL: https://7ecb8ff5.volunteer-ekr.pages.dev
Branch Preview URL: https://feat-98-file-upload-api.volunteer-ekr.pages.dev

View logs

add a public api to fetch public files from r2.
add a private api to fetch protected files from r2.
add a data function to fetch file info from uploads table.
@manvinderjit manvinderjit changed the title WIP - Feat/98 file upload api Feat/98 file upload api Aug 10, 2025
@manvinderjit manvinderjit requested a review from bcha92 August 10, 2025 22:21
@manvinderjit manvinderjit marked this pull request as ready for review August 10, 2025 22:21
Comment thread api/src/routes/files/data.ts Outdated
Comment thread api/src/routes/files/data.ts Outdated
Comment thread api/src/routes/files/data.ts Outdated
Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts
Comment thread api/src/routes/files/validation.ts Outdated
Comment thread api/src/routes/files/validation.ts
Comment thread api/src/routes/files/validation.ts
manvinderjit and others added 7 commits August 11, 2025 16:54
Co-authored-by: Marco Campos <me@madcampos.dev>
Co-authored-by: Marco Campos <me@madcampos.dev>
move file access level check after validating file extension
reverse the logic in accessLevelCheck for files.
delete orphaned file from r2 if file data not stored in database.

@kbventures kbventures left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work.

Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts Outdated
Comment thread api/src/routes/files/index.ts
Comment thread api/src/routes/files/validation.ts Outdated
remove unwanted comments from files/index.ts
remove unwanted comments from files/validation.ts
rename the file schema migration from user-uploads to create-uploads.
add a filename field to keep the filename separate from id.
remove the accessLevel field, enabling only public types.
update avatar url in the profile table instead of creating a separate uploads table.
delete uploads table.
clean up file validation methods based on public and private access.
update the POST files/upload api to upload avatar in Profile table.
update the GET files/ api to allow public file access from R2 bucket using file prefix.

@kbventures kbventures left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include at least one hurl interagration tests and create a github issue to create unit tests for this feature(image upload). Our unit tests setup is almost ready.

defaultHook: statusResponseFormatter
});

// NOTE: Add more specific GET routes before the following route only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love to see this new cool feature.

Some comments.

A public service for a resource which cost money? That sounds like a bad idea for whomevers credit card goes into the Cloudflare account. The service needs to be scoped
to retreving Avatars ONLY and with authentication.

@kbventures kbventures Nov 3, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're building a image uplaod service specificaly not a file upload service. I think the naming should reflect that and has mentioned above scoped for that specifially.

@kbventures kbventures Nov 3, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per our conversation, we need to code a check to ensure we don't go voer the "free" tier limit. There's no way to to have alarms or limits setup at the admin console level. Checking everything we utilize(resource) is not optimal but we can find a more optimal way after the MVP is in production.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the limiter. If we are using a tier-limited service, we would need to manually setup a logger that tracks this and send an alert once it reaches a certain threshold.

@manvinderjit

Copy link
Copy Markdown
Collaborator Author

Status Update: On hold due to infrastructure decision delegation for Cloudflare R2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend/API 🍑 Anything related to the backend or API side of things

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File upload API

4 participants