Skip to content

Instantly share code, notes, and snippets.

@jaidevd
Created December 13, 2022 08:01
Show Gist options
  • Save jaidevd/83bd512ccabdb6ea451d629700622c28 to your computer and use it in GitHub Desktop.
Save jaidevd/83bd512ccabdb6ea451d629700622c28 to your computer and use it in GitHub Desktop.
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