Store Book Files and Covers
Store Book Files and Covers
Task
Store the EPUB and any derived cover asset separately so the Library can display real book metadata.
Keep storage keys on the Book record rather than exposing raw filesystem paths.
A useful shape is:
users/<user-id>/books/<book-id>/book.epub
users/<user-id>/books/<book-id>/cover.<ext>
Create the Book ID first when you need stable object-key naming:
const book = await prisma.book.create({
data: {
userId: user.id,
title,
author,
epubKey: "",
},
});
Upload using the Book ID, then update the record with the final key. If any upload fails, remove the partially created record and objects.
If the EPUB parser extracts a cover, store the cover as a separate object and save its key.
Do not make the object bucket public merely to simplify access. Use authenticated routes or signed URLs for private books.
Test
Upload an EPUB that has a cover.
Confirm:
- EPUB object exists
- cover object exists when available
- Book stores their keys
- Library displays the cover
Checkpoint
Readly stores both the source EPUB and its display assets in user-scoped object storage.