opengovsg / starter-kit

A technical kit to quickly build new products
https://start.open.gov.sg
MIT License
36 stars 6 forks source link

Incorrect R2 variable name leads to error "Avatar upload feature is not enabled" #164

Closed handshou closed 8 months ago

handshou commented 1 year ago

Describe the bug Implementing avatar upload feature by entering R2 environment variables leads to an error toast message, "Avatar upload feature is not enabled".

On further inspection, the environment variable R2_BUCKET_NAME is incorrectly named. Correct name is R2_AVATARS_BUCKET_NAME.

To Reproduce Steps to reproduce the behavior:

  1. Add R2 environment variables to .env.development.local or creating Vercel project environment variables.
  2. Start environment if running dev locally
  3. Go to /profile
  4. Click on profile picture, select a photo to upload
  5. See error Avatar upload feature is not enabled.

Expected behavior Be able to upload a photo after adding R2 environment variables.

Additional context The issue is a relatively easy find, but what made it frustrating was trying to find the right variables on Cloudflare. After ensuring all variables were correct, CORS was fine, and then running into this issue almost made me flip the table.

See where the variable is referenced, https://github.com/opengovsg/starter-kit/blob/d6d0265d17bcb8d3525dda62a98919db9d969710/src/server/modules/storage/storage.router.ts#L23

handshou commented 1 year ago

Documentation requires env var name change too.

Screenshot 2023-07-13 at 6 55 42 PM

See end of page, https://start.open.gov.sg/docs/optional-features/storage

karrui commented 8 months ago

We've updated the env vars to use a single bucket (and subdirectories) via a combination of R2_IMAGES_DIRECTORY. Updated the docs to reflect this https://github.com/opengovsg/starter-kit-docs/pull/37