【发布时间】:2018-04-22 01:53:49
【问题描述】:
您好,我在从我的 python 客户端接收我的烧瓶服务器上的文件时遇到问题我正在将屏幕截图保存在内存中,但无法在服务器端接收它。感谢我能得到的任何帮助
服务器代码:
@app.route('/upload', methods=['POST'])
def upload():
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['upload_folder'], filename))
客户代码:
content_type = 'image/jpeg'
headers = {'content-type': content_type}
from PIL import ImageGrab
from StringIO import StringIO
screen = ImageGrab.grab()
img = stringIO()
screen.save(img, 'JPEG')
img.seek(0)
fd = open('screen.jpg', 'wb')
fd.write(img.getvalue())
fd.close()
fin = open('screen.jpg', 'wb')
files = {'file': fin}
requests.post('http://localhost/upload', files=files)
【问题讨论】:
-
files={'file': ('test.jpg', content_type)}你的图片数据在哪里? -
感谢您的回复我已经更新了代码,并且可以将图像保存到磁盘并毫无问题地发布,但我想了解如何在不将其保存到磁盘的情况下仍然可以发布图像。