Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services AWS Chalice-将文件作为响应发送_Amazon Web Services_Aws Lambda_Aws Api Gateway_Chalice - Fatal编程技术网

Amazon web services AWS Chalice-将文件作为响应发送

Amazon web services AWS Chalice-将文件作为响应发送,amazon-web-services,aws-lambda,aws-api-gateway,chalice,Amazon Web Services,Aws Lambda,Aws Api Gateway,Chalice,我目前有一个API设置,如下所示 @app.route('/', cors=cors_config, methods=['GET']) def index(): request = app.current_request file_name = "orders.csv" file_path = '/tmp/{}_{}'.format("Life", file_name) with open(file_path, 'w') as csvFile:

我目前有一个API设置,如下所示

@app.route('/', cors=cors_config, methods=['GET'])
def index():
    request = app.current_request

    file_name = "orders.csv"
    file_path = '/tmp/{}_{}'.format("Life", file_name)

    with open(file_path, 'w') as csvFile:
        field_names = ["OrderID", "OrderedBy", "Agent"]
        writer = csv.DictWriter(csvFile, fieldnames=field_names)
        writer.writeheader()
        for item in range(10):
            writer.writerow(
                rowdict={
                    "OrderID": str(1), 
                    "OrderedBy": "noob",
                    "Agent": "pro"
                }
            )
        csvFile.close()

    with open(file_path, 'rb') as f:
        contents = f.read()
    f.close()

    file_size = os.path.getsize(file_path)

    headers = {'Content-Type': 'application/octet-stream', 
        'Content-Disposition': 'attachment; filename={}'.format(file_name),
        'Content-Length': str(os.path.getsize(file_path))
    }
    return Response(body=contents, headers=headers)
现在,当使用运行此代码时,我可以下载在这里创建的文件,而不会出现任何问题。但是,在将其部署到我的AWS帐户后,API端点允许我下载一个文件,但它包含我想要的文件的二进制字符串。我阅读了一些其他帖子,其中指出要更新contentHandling路径,将_转换为_BINARY(),然后从API网关内部重新部署API(而不是通过chalice部署)。它仍然表现出同样的行为

有什么办法解决这个问题吗