gpt4 book ai didi

python - Swagger/OpenAPI 规范的特点是文件上传被 Google Endpoints 拒绝

转载 作者:行者123 更新时间:2023-12-02 04:24:07 25 4
gpt4 key购买 nike

我的目标是设置一个简单的 API,用于通过 Google Endpoints 上传文件。

这是我简化的 OpenAPI 规范,根据 Swagger 验证它是有效的:

swagger: "2.0"
info:
title: "JSON Ingester"
description: "Receive JSON files, transform and load them."
version: "1.0.0"

host: "project-id.appspot.com"
schemes:
- "https"

paths:
/uploadFile:
post:
operationId: uploadFile
consumes:
- multipart/form-data
parameters:
-
in: formData
name: upfile
type: file
description: file
responses:
200:
description: "File uploaded."
400:
description: "Error during file upload."

我总是得到这个晦涩的错误消息:

user@cloudshell:~/google-cloud-json-ingester (project-id)$ gcloud endpoints services deploy ./openapi.yaml
ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Cannot convert to service config.
'location: "openapi.yaml: Operation \'post\' in path \'/uploadFile\'"
message: "Operation does not require an API key; callers may invoke the method without specifying an associated API-consuming project. To enable API key all the SecurityRequirement Objects (https://gi
thub.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-requirement-object) inside security definition must reference at least one SecurityDefinition of type : \'apiKey\'."
location: "unknown location"
kind: ERROR
message: "http: repeated message field \'google.protobuf.Struct.fields\' referred to by message \'UploadFileRequest\' cannot be mapped as an HTTP parameter."
location: "unknown location"
kind: ERROR
message: "http: cyclic message field \'google.protobuf.Struct.FieldsEntry.value\' referred to by message \'UploadFileRequest\' in method \'method 1.project_id_appspot_com.UploadFile\' cannot
be mapped as an HTTP parameter."
location: "unknown location"
kind: ERROR
message: "http: cyclic message field \'google.protobuf.ListValue.values\' referred to by message \'UploadFileRequest\' in method \'method 1.project_id_appspot_com.UploadFile\' cannot be mapp
ed as an HTTP parameter."
'

对于可能的原因,我已经没有想法了。

有什么建议吗?

最佳答案

看起来它至少需要一些身份验证:https://cloud.google.com/endpoints/docs/openapi/authentication-method

我还认为 Cloud Endpoints 不支持类型:文件,因此您必须使用类型:字符串并使用相当于curl -X POST -F“file_upload=@file.txt”http://myservice.com/endpoint 上传。

关于python - Swagger/OpenAPI 规范的特点是文件上传被 Google Endpoints 拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56854100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com