internetarchive / internetarchive/openlibrary

Enable Direct Profile Picture Uploads on Open Library

Open
#13,263 5 comments 0 reactions 1 assignee Claimed by @RsbhThakur View on GitHub
Lead: @RayBB Needs: Review Assignee Priority: 3
Dominant language
Python
Stars
6.7k
Forks
2k
Avg merge
2d 19h
Merged PRs (30d)
138

Description

## Problem / Opportunity

* **Problem:** Currently, Open Library users cannot upload or change their profile picture (avatar) directly on the platform. The avatar URL is generated via `https://archive.org/services/img/{itemname}` (where `itemname` is the user's Internet Archive item ID, typically `@username`). To update their profile picture, users have to leave Open Library, navigate to Archive.org, log in there, locate their account item page, and upload their image there.
* **Justify:** This multi-step, multi-site journey is extremely counter-intuitive. Users expect to edit all their profile details in one place. As a direct result, **Lisa and the helpdesk support team receive a steady, high volume of support inquiries** from users asking how to update their profile picture or reporting it as broken/missing.
* **Success Criteria:** Users should be able to upload, update, and delete their profile picture directly from the edit profile page on Open Library. The new profile picture should show up immediately across the site (without waiting for the 24-hour cache expiry).

## Proposal

* Add an image file input (with format/size validation) to the profile edit form.
* Create a FastAPI endpoint (e.g. `POST /account/avatar`) to receive the uploaded image.
* Use the logged-in patron's decrypted `s3_keys` (via `get_s3_keys(account)`) to upload the image directly to their Internet Archive account item (typically `@username`) using the `internetarchive` Python SDK or S3 API.
* Invalidate the `User.get_avatar_url` cache upon a successful upload so the change is immediately visible.

## Breakdown

Implementation Details (for maintainers)

#### Related files
Refer to [this map of common Endpoints](https://docs.openlibrary.org/developers/backend/endpoints.html):
* [`openlibrary/core/models.py`](https://github.com/internetarchive/openlibrary/blob/master/openlibrary/core/models.py) - Contains `get_avatar_url` which generates the avatar link from the Archive.org item.
* [`openlibrary/plugins/upstream/mybooks.py`](https://github.com/internetarchive/openlibrary/blob/master/openlibrary/plugins/upstream/mybooks.py) - Defines the `/people/{username}/avatar` endpoint which performs a redirect.
* [`openlibrary/templates/type/user/edit.html`](https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/type/user/edit.html) - The template for the edit profile form.
* [`openlibrary/templates/account.html`](https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/account.html) - Links to `/people/{username}?m=edit`.
* [`openlibrary/fastapi/account.py`](https://github.com/internetarchive/openlibrary/blob/master/openlibrary/fastapi/account.py) - Place for new FastAPI endpoints for handling account modifications.

#### Requirements Checklist
* [ ] Add an image file input (with format/size validation) on the profile edit form.
* [ ] Implement a FastAPI endpoint (e.g. `POST /account/avatar`) to receive the uploaded image.
* [ ] Use `get_s3_keys` to authenticate and upload the photo to the user's Internet Archive item (`@username`) using the `internetarchive` Python SDK or S3 API.
* [ ] Invalidate the `User.get_avatar_url` cache upon a successful upload.
* [ ] Update documentation to guide users on the new upload feature, and update any helpdesk guides.

#### Stakeholders
* **@seabelis** (Community Manager & Support Lead) - Primary contact for user feedback and support coordination.
* Backend Leads / Security team - To review S3 upload policies, rate limits, and allowed image formats.


#### Instructions for Contributors
* **Before** [creating a new branch](https://docs.openlibrary.org/developers/tools/git.html#making-changes-and-creating-a-pull-request) or pushing up changes to a PR, please first [run these commands](https://docs.openlibrary.org/developers/tools/git.html#working-on-your-branch) to ensure your repository is up to date, as the pre-commit bot may add commits to your PRs upstream.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.