In this blog, we will talk about how to add feature of loading system image of event topic from server to display it on Open Event Server. The focus is on adding a helper function to create system image and loading that local image onto server.
Helper function
In this feature, we are providing feature of addition of loading default system image if user doesn’t provides that.
- First we get a suitable filename for a image file using get_file_name() function.
- After getting filename, we check if the url provided by user is a valid url or not.
- If the url is invalid then we use the default system image as the image of that particular event topic.
- After getting the local image then we read that image, if the given image file or the default image is not readable or gives IOError then we send a message to the user that Image url is invalid.
- After successful reading of image we upload the image to event_topic directory in static directory of the project.
- After uploading of this image we get a local URL which shows where is the image is stored. This path is stored into database and finally we can display this image.
Resources
- Documentation | Input / Output in python: https://docs.python.org/3/tutorial/inputoutput.html
- Documentation | Uploading files in Flask: http://flask.pocoo.org/docs/1.0/patterns/fileuploads/