server
from flask import Flask, request
app = Flask(__name__)
@app.route('/test_download', methods=['GET', 'POST'])
def receive_data():
if request.method == 'POST':
f = request.files['file']
f.save(r'G:\server_recv.png')
with open(r'G:\1.png', 'rb') as f:
content = f.read()
return content
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
client
import requests
files = {"file": open(r'G:\2.png', "rb")}
r = requests.post('http://127.0.0.1:5000/test_download', files=files, stream=True, timeout=500)
print r.status_code
f = open(r'G:\download.png', 'wb')
for c in r.iter_content(chunk_size=1024):
f.write(c)