Skip to content

Upload the PDF into the SQLite database#4

Open
oliviayixincai wants to merge 3 commits intoadanomad:mainfrom
oliviayixincai:upload-pdf-into-sqlite
Open

Upload the PDF into the SQLite database#4
oliviayixincai wants to merge 3 commits intoadanomad:mainfrom
oliviayixincai:upload-pdf-into-sqlite

Conversation

@oliviayixincai
Copy link

Summary of PDF Upload Feature Implementation

Overview

In this update, I implemented the feature to upload PDF files into the SQLite database. This enhancement allows the application to store PDF documents directly in the database, facilitating easier management and retrieval of PDF files.

Approach

  1. Client-Side Base64 Encoding: The PDF file is read and converted to a base64 string on the client side before being uploaded.
  2. Database Schema Update: The SQLite database schema was updated to include a new table for storing PDF files. This table includes fields for the PDF ID, base64-encoded data, and other relevant metadata.
  3. API Endpoint: A new API endpoint was created to handle the PDF upload requests. This endpoint receives the base64-encoded PDF data and stores it in the SQLite database.

Code Changes

  • PDF Storage Class: The PdfStorage class was updated to include methods for saving and retrieving PDFs in base64 format.
  • API Route:
    • Route POST /api/pdf was added to handle the PDF upload requests. This route processes the incoming PDF data and stores it in the database.
    • Route GET /api/pdf was added to handle the PDF retrieval requests. This route retrieves the PDF data from the database and returns it to the client.
  • Database Utility: The SQLiteDatabase class was updated to include methods for saving and retrieving base64-encoded PDFs.
  • PDF Utilities: Added lines to handle the PDF upload process in pdfUtils.ts.
  • Client-Side Upload: The client-side code was updated to upload it to the server.

Challenges

Understanding Frontend PDF Handling

One of the main challenges was understanding how the PDF file was handled on the frontend and finding the right place to upload it to the backend.

Solution: I thoroughly reviewed the existing frontend code to understand the flow of PDF handling. This helped me identify the appropriate place to integrate the upload functionality.

Getting Familiar with SQLite Backend

Another challenge was getting familiar with the SQLite backend, as it was crucial for storing and retrieving the PDF data.

Solution: I spent time learning the SQLite database operations and how to integrate them with the existing codebase. This included understanding the schema, writing queries, and handling database connections.

Future Work

Although the endpoint to retrieve stored PDFs from the database is already implemented, the frontend code to actually fetch and display these PDFs in the UI has not been developed yet. The next step would be to implement the functionality to fetch the stored PDFs from the database and render them in the application's UI. This will complete the end-to-end process of uploading, storing, and displaying PDFs.


Disclaimer: This summary was drafted with the assistance of ChatGPT.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants