Abadi 2 2 silver badges 7 7 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Who owns this outage? Building intelligent escalation chains for modern SRE. Podcast Who is building clouds for the independent developer? Featured on Meta.
Now live: A fully responsive profile. Reducing the weight of our footer. Related First step is to create a project root directory under which I will put all the required files for the project. Create the below app. This file should be created under the project root directory. Notice how I create flask instance. Next I will create main. In the above source code, the root path or endpoint will simply render the UI.
This UI contains only one link for downloading a file from the server. Clicking on the link will ask user to save the file in a chosen location. The file type could be anything. As you see I have tested with four types of files. I hope this example will work with other file types as well.
Now create a download. Above line creates a uploads folder in the same directory where the src code of the site is stored. We should also check for file extension that the user is uploading as there would be some specific type of file that the site can process.
Also there is security issue if the user can upload any type of file. User might upload html file that can cause XSS cross site-scripting problems. For this post, we only need pdf file extensions as this Flask app would remove watermark from pdf files created by CamScanner App Famous App for scanning documents through Mobile Camera.
Pdf files would have watermark at the bottom similar to what is shown in the image below :. Function checks the filename for allowed file extension and if file type is supported the function returns True otherwise it returns False. We can add more extension types in allowed extensions set for supporting different type of file uploads. It returns the index. Uploaded file attached in the POST request can be referenced by request.
0コメント