PixelStorageOne is an open-source utility for deconstructing and retrieving images and zip files. It provides a simple interface to store and retrieve binary data from a MySQL database, allowing the content to be easily accessed from another location, service or recalled on demand.
This can be used to handle storage for website images, file upload storage and more.
- The ability to store file data via a database
- Support for both image files and zip archives
- Easy to configure SQL credentials in the config file
- Flexible module to customise to fit your requirements
- Alternative low-cost storage of data compared to hosting services
- Python 3
- MySQL Database
-
Clone the repository:
git clone https://github.com/Azio0/PixelStorageOne.git cd PixelStorageOne -
Install Python and PIP:
sudo apt-get install python3 sudo apt-get install python3-pip
-
Install the required Python Packages:
pip install -r requirements.txt
-
Modify the MySQL Database details:
cd source/utils/config edit the databse section in config.yml -
Call the setup database function on initial setup:
make a .py file and import PixelStorageOne inside the file call PSO.setup.database() -
Move the module into your source code, and reference PixelStorageOne to call the class methods. An example is below showcasing how this can be done.
PixelStorageOne uses the following components:
- Configuration: Reads configuration settings from a YAML file.
- Database: Manages connections and queries to a MySQL database.
- Transaction: Generates unique receipt UIDs for transactions.
- Pillow: Handles image processing and encoding.
- ZipArchive: Handles zip file processing and encoding.
The PixelStorageOne class provides methods to deconstruct and retrieve images and zip files. It has two main nested classes: deconstruct and retrieve.
Deconstructs an image file, encodes it in base64, and stores it in the database.
- Parameters:
image_path(str) - The path to the image file. - Returns: A tuple containing the receipt UID and status code.
Deconstructs a zip file, encodes it in base64, and stores it in the database.
- Parameters:
zip_path(str) - The path to the zip file. - Returns: A tuple containing the receipt UID and status code.
Retrieves an image from the database using the receipt UID.
- Parameters:
receiptUID(str) - The unique identifier for the image. - Returns: A tuple containing the image data and status code.
Retrieves a zip file from the database using the receipt UID.
- Parameters:
receiptUID(str) - The unique identifier for the zip file. - Returns: A tuple containing the zip file data and status code.
Refer to the basic_use.py file for an example of how to use the PixelStorageOne class.
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'source')))
from psom import PixelStorageOne
# Create an instance of the PixelStorageOne class
PSO = PixelStorageOne()
# Image deconstruction and retrieval
def image(x):
# Deconstruct an image
receiptUID, status = PSO.deconstruct.Image(x)
print(receiptUID, status)
if status != 200:
return f"Error: {receiptUID}"
# Retrieve an image
image_data, status = PSO.retrieve.Image(receiptUID)
print(image_data, status)
if status != 200:
return f"Error: {image_data}"
return "Image deconstruction and retrieval successful"
# Zip file deconstruction and retrieval
def zip_file(y):
# Deconstruct a zip file
receiptUID, status = PSO.deconstruct.ZipFile(y)
print(receiptUID, status)
if status != 200:
return f"Error: {receiptUID}"
# Retrieve a zip file
zip_data, status = PSO.retrieve.ZipFile(receiptUID)
print(zip_data, status)
if status != 200:
return f"Error: {zip_data}"
return "Zip file deconstruction and retrieval successful"
image_path = input('Image Path: > ')
image_example = image(image_path)
print(image_example)
zip_path = input('Zip Path: > ')
zip_example = zip_file(zip_path)
print(zip_example)This is an open-source project, and contributions are welcome. Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License.
For any questions or suggestions, please open an issue or contact the project maintainers.
This project is intended to be open-source and free from cost to use. I love coding, setting a target and accomplishing it, sometimes by using pre-existing technology or creating an original approach to a problem. It excites me and gives me a sense of purpose, but it is not always easy to find the time or motivation to keep pushing forward. Donations are welcome if you wish to give something towards the work I do, but it is completely optional and is certainly not a requirement.
