Skip to content

Implement S3 deletion for user profile images #27

Closed

Description

@atomnoid

What happened

When user profile images are stored in S3, deleting the profile image only updates the user's database record to user.svg. The previously uploaded image remains in the S3 bucket.

The userImageDelete method in api/src/controllers/users.controller.js currently contains a TODO for S3 deletion.

What I expected instead

When STORAGE_TYPE=s3, deleting a user's profile image should also remove the corresponding object from S3 before/while resetting the user's image reference to user.svg.

When local storage is used, the existing local-storage behavior should remain unchanged.

Acceptance criteria

  • In S3 mode, deleting a profile image removes the user's currently saved profile-image object from the configured S3 bucket.
  • The server does not choose the S3 object to delete from client-supplied req.body.data alone; it resolves the target user and uses the stored user image or verifies the supplied image matches that stored value.
  • S3 deletion is limited to the expected profile-image object path/prefix, such as uploads/user_images/, so this endpoint cannot delete item images, backups, documents, or arbitrary bucket keys.
  • The default/shared user.svg image is never deleted.
  • Local-storage behavior remains unchanged.
  • If the S3 delete fails, the API does not silently report full success while leaving the object behind unless a reviewed retry/audit path is added.
  • Tests cover successful S3 deletion, local-storage no-op, default-image no-op, invalid URL/key no-op, arbitrary same-bucket key rejection, and S3 failure handling.
  • The touched files pass the API formatter/lint check used by CI.

Steps to reproduce

  1. Configure Posnic to use S3 storage.
  2. Upload a user profile image.
  3. Confirm the image is stored in the configured S3 bucket.
  4. Delete the user's profile image.
  5. Check the user's profile and the S3 bucket.

How often

Every time an S3-hosted user profile image is deleted.

Your setup

  • Posnic version: main
  • Operating system: any
  • Using Posnic Cloud: no
  • Hardware involved: N/A

Log

No error is necessarily reported because the database update succeeds even though the S3 object remains.

Anything else

The upload path already supports S3 storage. The deletion path currently contains a TODO for S3 deletion, so this issue is specifically about completing that missing S3 cleanup behavior.

Activity

  1. added
    bug
    on Sep 1, 2026
  2. atomnoid commented on Sep 1, 2026

    @atomnoid
    ContributorAuthor

    Hi @sridharkalaibala I’d like to work on this issue.

    I traced the current flow and found that S3 upload is already implemented,
    while userImageDelete currently resets the database reference to
    user.svg without removing the corresponding S3 object.

    I’ll keep the change scoped to the S3 deletion path and add regression
    coverage for it.

  3. added
    help wanted
    size: medium
    on Sep 1, 2026
  4. sridharkalaibala commented on Sep 1, 2026

    @sridharkalaibala
    Contributor

    Thanks for picking this up. PR #28 is the right place to continue this work, and I re-reviewed the latest push there. The scope is still useful, but there is one remaining blocker: the delete validation needs to match the way uploadUserImage() stores S3 keys today, and Prettier still needs to pass on the touched files.

    Let's keep the detailed review in #28 so this issue stays clean.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wantedsize: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions