This project is my personal Web API to upload images to an online web server.
Imagine you are working on a programming project that requires you to share images.
How will you share those images to people that use other computers?
Where will you host those images and access them through code?
Well, I have answered those questions for myself by building this project.
- I will share images to people of other computer by uploading those images online and sharing the url of the image
- I will host them in my own web server that has a web service that gives me back the url for the images I uploaded
My Web API has three routes:
- /upload: Route used to upload images to the server (POST Request Only)
- /delete: Route used to delete images to the server (POST Request Only)
- /pics: Route used to show images stored in the web server (GET Request Only)
My Web API takes a JSON string with the following fields for the /upload route:
- key: API KEY required to use the API
- imgbase64: Base 64 Code that contains the data that describes the image
- name: Name the user wants for this image to have
The imgbase64 field expects the HTML Base 64 encoded version for image data that follows the following format:
data:[mediatype];base64,
Example:
data:image/png;base64,{base64 pure code starts from here on}
A successful response for the /upload route will contain this following JSON field:
- img_url: URL to the image the user just uploaded through Base 64 Code
My Web API takes a JSON string with the following fields for the /delete route:
- key: API KEY required to used the API
- imgurl: URL for the image hosted in the web server that is to be deleted
A successful response for the /delete route will contain this following JSON field:
- message: A confirmation that contains the old URL of the deleted image which leads to a 404 response
An erroneous response for either the /upload route the /delete route will contain the following JSON field:
- error: Description of the error raised
To trigger a successful response from the /pics route:
- Trigger a GET request to
https://py-pic-box.vercel.app/pics/{image-filename}
- Receive the image
The following technologies were required to compelte this project
- Python
- Flask
© josewebdev2000 2024