我正在尝试使用 falcon 框架作为后端来接收 pdf 文件。我是后端的初学者,并试图了解正在发生的事情。所以总结一下,有2个类。其中之一是我正在工作的朋友。
这是后端代码:
#this is my code
class VehiclePolicyResource(object):
def on_post(self, req, resp, reg):
local_path = create_local_path(req.url, req.content_type)
with open(local_path, 'wb') as temp_file:
body = req.stream.read()
temp_file.write(body)
#this is my friend code
class VehicleOdometerResource(object):
def on_post(self, req, resp, reg):
local_path = create_local_path(req.url, req.content_type)
with open(local_path, 'wb') as temp_file:
body = req.stream.read()
temp_file.write(body)
它完全一样并且没有给出相同的答案,我通过这样做添加了路线
api.add_route('/v1/files/{reg}/policies',VehicleResourcesV1.VehiclePolicyResource())
并通过在终端中使用此命令:
HTTP POST localhost:5000/v1/files/SJQ52883Y/policies@/Users/alfreddatui/Autoarmour/aa-atlas/static/asd.pdf
它试图获取文件。但它一直说,不支持的媒体类型。而其他代码,接收图像,与上面的代码相同,它可以工作。
任何想法 ?