Great, now we're using base64 strings in our SQLite database to store images... let's talk about why that actually kinda sucks.
CPU performance: Base64 encoding is an expensive CPU-intensive operation. If we have a lot of uploads (I mean, we're planning on being a successful company, right?), we'll have some scaling issues.
Storage costs: Base64 encoding bloats the size of the image data. We're using more disk space than we need to, which again, is expensive and slow.
Database performance: Databases (especially relational databases like SQLite, Postgres and MySQL) are optimized for small, structured data, not giant blobs of binary. It will impact query performance in a non-trivial way.
Caching: Base64 encoded images aren't as cache friendly as raw files, meaning slower load times and higher bandwidth costs.
It's usually a bad idea to store large binary blobs in a database, there are exceptions, but they are rare. So what's the solution? Store the files on the file system. File systems are optimized for storing and serving files, and they do it well.
Assignment
Let's update our handler to store the files on the file system. We'll save uploaded files to the /assets directory on disk.