首页 > 解决方案 > Pistache 服务器如何处理文件上传?

问题描述

我在 openapi 3.0 中创建了一个用于文件上传的 api。我的 YAML 文件如下所示

paths:
  /upload:
    post:
      description: Upload a single Audio File
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                upload:
                  type: string
                  format: binary
      responses:
        '200':
          description: Successful to Upload file
          
        '400':  
          description: Fail to Upload File

在服务器端,我的文件上传部分现在看起来像这样

void DefaultApiImpl::upload_post(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){
    
    
    response.send(Pistache::Http::Code::Ok, "File Upload Complete..................... \n");
}

当我尝试使用 api 上传任何文件时,我也会得到响应。问题是我没有为服务器端获取任何资源来将文件存储在特定文件夹或目标中。我在服务器端缺少什么?

标签: c++httpfile-uploadserveropenapi

解决方案


推荐阅读