This is an archived copy of a previous semester's site.
Please see the current semester's site.
MP 2 had you implement part of the PNG specification and hide arbitrary payloads inside a special uiuc
chunk of them. This MP has you wrap that MP in a web microservice so that it can be run by visiting a website rather than by having the source code on hand.
In your CS 340 directory, merge the initial starting files with the following commands:
git fetch release
git merge release/mp6 --allow-unrelated-histories -m "Merging initial files"
Complete the app.py
program using the Python flask
library to create a web-based service that has two different routes.
GET /extract/<image_num>
Return a previously extracted hidden GIF, based on the image_num
index.
<image_num>
th GIF exists in your local cache, the <image_num>
th hidden GIF file is returned.flask
program has not received <image_num>
GIFs, a HTTP 404: Not Found
response must be returned.<image_num>
cache must save the first extracted image as index 0
.This assumes that you have a local cache, a list of successful returns from POST /extract
. For consistency during testing, this should be an in-memory (not on-disk) cache.
As part of the POST /extract
route, you will need to use your mp2 png-extractGIF
program. You may want to verify that your png-extractGIF
program is complete and functional and that you can run the following commands:
Makefile
in the MP6 directory so you can use make
in mp6
to compile png-extractGIF
into your mp6
directory. This uses your code from your mp2
directory.
./png-extractGIF
works before trying to use it in Python../png-extractGIF sample/luther.png polyhedron.gif
. (This should successfully save polyhedron.gif
.)Additionally, you should verify your MP2 solution returns unique values for main
for the different features you need to identify in Python:
0
(the convention for successful execution),uiuc
chunk, should return a different non-zero value.You may need to modify your MP2 program slightly to fix any bugs to ensure your program can work with your new microservice.
If you didn’t do MP2 or its not readily fixable, we include just enough of a solution for this use case in the png-extractGIF-minimal.c
including in the MP 6 starter files. If you overwrite MP 2’s png-extractGIF.c
with this file it won’t pass all of MP2’s tests, but it does enough to pass this MP’s tests.
There will be a few tasks you will need to complete in Python:
You will need to store the files being sent on your computer. We recommend using a directory named temp
, and have set up the provided .gitignore
to ignore that directory on a git push
and avoid cluttering up your github.
If you do use a directory, create it from inside Python using os.makedirs
function
You will need to retrieve the file sent in the request. The parsed request body is available through the request
object imported from flask
; submitted files are in request.files
, and for this particular web API in request.files['png']
.
You will need to run a compiled executable from within Python and check its exit code. You can do this with os.system
function or the subprocess.run
function. subprocess.run
is newer and much more versatile, but os.system
is simpler to use and available on older versions of Python.
Flask’s send_file
function is likely to be useful in sending the extracted file back to the requester.
If anything goes wrong, you should return "Error Message", 500
to return an error (but change Error Message
to something useful).
Launch your service by starting your flask application:
python3 -m flask run
Then, you can test your program in two different ways:
By using your web browser and visiting your flask server (ex: http://127.0.0.1:5000/
).
By the command line, using curl
to make a request to your web server: curl -f -o output.gif http://localhost:5000/extract -F "png=@sample/luther.png"
@sample/luther.png
with another file. Ensure that you keep the @
symbol to tell curl
to send the contents of the file, not just the file name.output.gif
to ensure the extraction was successful.uiuc
chunk.A pytest
suite is provided for you.
test_flask.py
test cases tests your code locally (it uses make
to build your mp2
, and requires your mp2
to be working).test_vm.py
test cases tests your VM deployment.To run only the Part 1 test cases, run:
python3 -m pytest test_flask.py
You have a Virtual Machine (VM) provided for you as part of being in CS 340. If you have not done so already, learn more about your VM on our VM page.
You might need to install additional libraries to get your VM fully set up. For systems packages you can use something like sudo apt-get install gcc
. For python libraries, you can use something like python3 -mpip install requests
. A list of python packages you might need for this MP is included in the requirements.txt
file.
We identify your VM for testing by the NETID.txt
file.
NETID.txt
to have your University of Illinois NetID. (Include only the NetID portion, NOT your full e-mail.)The NETID.txt file contains the NetID "netid", but no such entry can be mapped to a VM.
At the time you run your GitHub Action for grading, you server must be running on your VM using port 5000
(the default flask port). Additionally, your service must be accessible to other machines than just localhost.
--host 0.0.0.0
. For example: python3 -m flask run --host 0.0.0.0
.Once you have locally passed all the tests, you will need to submit and grade your code. First commit using the standard git commands:
git add -A
git commit -m "MP submission"
git push
The initial grading is done via a manual GitHub Action. You MUST complete this step before the deadline to earn any points for the MP:
ActionTab
mp6 autograding
Run Workflowbutton (located on the blue bar)
Run Workflow
Points are allocated according to the GitHub Action score.