部署包含 "file" 类型参数的端点时出错
Error deploying endpoint containing parameter of type "file"
我正在尝试部署一个包含 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 目前不支持上传图片。
您可以先上传到Google云存储:
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 检索图像并执行处理。
我正在尝试部署一个包含 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 目前不支持上传图片。
您可以先上传到Google云存储: 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 检索图像并执行处理。