【问题标题】:Error deploying endpoint containing parameter of type "file"部署包含“文件”类型参数的端点时出错
【发布时间】:2017-08-20 22:07:38
【问题描述】:

我正在尝试部署一个包含 parameter of type file 的简单端点。

我正在使用gcloud service-management deploy 命令和以下符合 openapi 的 yaml:

swagger: "2.0"

info:
  description: "Image API"
  title: "Image API"
  version: "v1"

host: "image-api.endpoints.myproject.cloud.goog"
basePath: "/v1"

schemes:
- "https"

paths:
  "/images":
    post:
      description: "Adds an image"
      operationId: "add"
      consumes:
      - "multipart/form-data"      
      produces:
      - "application/json"
      responses:
        201:
          description: "An image create response"
          schema:
            $ref: "#/definitions/ImageResponse"
      parameters:
      - name: filepath
        in: formData
        required: true
        type: string
      - name: image
        in: formData
        required: false
        type: file

definitions:
  ImageResponse:
    type: object
    properties:
      id:
        type: string
      url:
        type: string
      thumbnail_url:
        type: string

但出现以下错误:

 ERROR: unknown location: http: repeated message field 'google.protobuf.Struct.fields' referred to by message 'AddRequest' cann
ot be mapped as an HTTP parameter.
 ERROR: unknown location: http: cyclic message field 'google.protobuf.Struct.FieldsEntry.value' referred to by message 'AddRequ
est' cannot be mapped as an HTTP parameter.
 ERROR: unknown location: http: cyclic message field 'google.protobuf.ListValue.values' referred to by message 'AddRequest' can
not be mapped as an HTTP parameter.'

如果我将file 参数取出,则成功部署端点。 这是 Google Cloud Endpoint 限制还是有其他定义方式?

【问题讨论】:

    标签: google-cloud-endpoints gcloud openapi google-cloud-endpoints-v2


    【解决方案1】:

    Google Cloud Endpoints 目前不支持上传图片。

    您可以先上传到 Google Cloud Storage: https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload https://cloud.google.com/storage/docs/object-basics

    然后将 URL 传递给您的 Google Cloud Endpoints,然后它可以从 Google Cloud Storage 中检索图像并执行处理。

    【讨论】:

    • 我的后端可以接受端点上的文件,但 openapi.yaml 上没有文件参数。因此,您不会在文件参数上获得 Cloud Endpoints 功能语义,但请求/响应本身可以工作。这似乎比必须上传到云存储然后使用 blob id 调用端点要容易得多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-02
    • 1970-01-01
    • 2017-06-19
    • 2012-02-03
    • 2022-12-19
    相关资源
    最近更新 更多