-
Notifications
You must be signed in to change notification settings - Fork 4
View Photo From Database
In order to test the API, there needs to be an easy way to verify that a photo was sent to the database and stored properly. The easiest way to do this is to actually view the data that was sent to the database in image format. Python's Pillow (forked from PIL) allows photo manipulation, but can also recognize a couple formats of data from just the data itself. Here I will show the use of a tool written to view a photo from the database and steps required to view the photo from a computer.
- You must have either a Linux machine or something with X forwarding capabilities, if not you will not be able to display the photo on-screen and only be able to save the photo, copy it, and view it on your computer.
This tool takes in only a few parameters at the time of writing this. Those are
ticket-id,display, andsave. Here I will explain the use of each and then provide a few examples of usinggetphoto. A brief description of these will also be available as help from the CLI by passing-h.
ticket-id- This argument represents the ticketID in the ticketapi.Ticket table. If this argument is not provided--ticket-idor-t, then the last photo in the database will be retrieved.save- this must be passed in as either--saveor-sand takes a filename. It is important to not that it does not take in a filepath, but a filename. The image retrieved from the database will be saved in the ticket-api root under saved_photos (e.g. /var/www/html/ticketapi/saved_photos/filename). This must also include the extension you want to save the photo as.display- this must be passed in as either--displayor-dand requires an X session to display. This function will useImageMagickto display the PIL image loaded from the database.
You must be in the
/var/www/htmldirectory to run this app and you must run it as the ticket-api user. Since you may want to view the image in a window view X11 forwarding, I will give a brief tutorial on setting this up. It is impossible to login as theticket-apiuser via a password so you must first login to another user with X11 forwarding and setupxauthon theticket-apiuser after switching users (Don't worry this is super simple!).
- Login with X and setup
xauthwith theticket-apiuser
# ssh in normally to your user with X11 forwarding
ssh -X <user>@<server address>
# keep note of the display that is used, it is important for the next command
# it will be similar to localhost:10.0 where 10.0 is the important part to take note of
echo $DISPLAY
# This will be a list of all xauths associated with your user currently, find the one
# that the above command showed and copy the whole line (the first part should have
# <url>/unix:<number> where number should be 10 or 10.0 or something of the sort)
xauth list
# login to the `ticket-api` user, this will require a password for the `ticket-api` user
su ticket-api
# paste the line copied above and place it in <line copied from above>
xauth add <line copied from above>
# change directories into the appropriate directory
cd /var/www/html
- Now you can use the
getphotoCLI utility, here are some example usages
python3 -m ticketapi.apps.getphoto -t 123 -d # display the photo for ticketID 123
python3 -m ticketapi.apps.getphoto -t 123 -s cat.jpg # save the photo for ticketID 123 as cat.jpg
python3 -m ticketapi.apps.getphoto -s cat.png # save the photo for the last entered ticketID as cat.png
python3 -m ticketapi.apps.getphoto -d # save the photo for the last entered ticketID as cat.png