Created
December 13, 2022 08:01
-
-
Save jaidevd/83bd512ccabdb6ea451d629700622c28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import request, Flask | |
app = Flask(__name__) | |
@app.route("/", methods=["POST"]) | |
def index(): | |
if request.content_type == 'application/pdf': | |
with open('request.pdf', 'wb') as fout: | |
fout.write(request.data) | |
print('The received PDF file is copied at filename.pdf') | |
return "File copied to server", 201 | |
return "Only PDFs are accepted.", 415 | |
# Client code | |
import requests | |
with open('pdf-to-send.pdf', 'rb') as fin: | |
data = fin.read() | |
requests.post('http://localhost:5000', data=data, headers={'Content-Type': 'application/pdf'}) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment