Breakthrough: Image storage and retrieval

Within my PetPals team, I have the responsibility of implementing and maintaining the backend functionality for the admin section of the app. An administrator has the ability to create, edit, and delete pet profiles and news blurbs. Our team decided that a relational database would serve best to fulfill these requirements. At the start of the project, I had great success in collaborating with my team to design and implement it using MySQL. When our team moved towards creating or browsing a pet profile, it became clear that we needed a solution for how to store and retrieve animal images.

I had two ideas. The first attempt was to save an image as a string in our MySQL database. I made the necessary changes to the database schema. To support interaction with the new tables, I also created SQL functions for managing table data. These are the CRUD functions – create, retrieve, update, and delete. Lastly, I had to implement a way for our python app to open up the image file, encode it using base64, and store it into the database. This is where I ran into issues. MySQL connector produced an error because it couldn’t create a named pipe.

Prior to this, there would be no issues with MySQL connector because it used TCP/IP. The queries themselves did not communicate lots of data. But now with images, there was larger amounts of data. It made sense that MySQL connector would prefer to stream them. Doing so would avoid the timely costs in storing the data in the database. I referenced MySQL documentation but there was less info on configuring named pipes from existing databases. Doing a search, I found forums discussing related issues too. One solution was to give MySQL admin permissions on Windows. Another was to reinstall MySQL. During installation, I needed to change away from using the default TCP/IP to named pipes for the database communications. But after trying these with no success, I gave my second idea a go.

For my second idea, I would attempt using Github for image hosting and retrieval. I found a guide for how to make python code incorporate the Github API. First, I need to install PyGithub. Then, I needed to generate and save a Personal Access Token from Github. Lastly, I followed a guide’s template for connecting to the proper repo and creating a file on it. I began small. First, I uploaded a simple text file onto the repo. Then, it was an encoded image. Following feedback from my team, I then implemented image storage in its binary format. I also tested file retrieval and saving it locally. Having success with each of these steps, I achieve a significant breakthrough for image storage and retrieval.

Accordingly, I made updates so that my codebase could reflect the use of Github API for image storage and retrieval. I updated my database schema, made relevant functions for the new Images table structure, and implemented python code that used the Github API for the project needs.

One big takeaway is learning to rely on documentation. I looked up both MySQL and Github API documentation. And I wanted to see examples of them in use. So between guides and examples, I was able to locally test until I achieved my overarching goal of figuring out image storage and retrieval. Personally, I saw that perseverance is essential. There can be multiple ways of achieving the same goal. So if I hit roadblocks, I can look around for other options.

Print Friendly, PDF & Email

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *