在GCP API网关中上传文件
后端URL)创建以下 API配置
swagger: '2.0'
info:
title: upload
description: upload
version: 1.0.0
schemes:
- https
produces:
- application/json
security:
- api_key: [ ]
paths:
/upload:
post:
summary: uploads a file.
consumes:
- multipart/form-data
operationId: uploadFile
parameters:
- in: formData
name: file
description: The file to upload.
required: true
type: file
responses:
'200':
description: upload successful
x-google-backend:
address: https://XXXXX.XXXXX
path_translation: APPEND_PATH_TO_ADDRESS
securityDefinitions:
api_key:
type: "apiKey"
name: "key"
in: "query"
我正在尝试为 GCP API Gateway (OMMUTTENT的真实
网关api-configs create uploadConfig -api = [api] -openapi-spec = OpenApi.yaml -project = [myProject] -backend-auth-service-account = [account]
这将导致此错误消息:
错误:( gcloud.api-gateway.api-configs.create)invalid_argument:无法转换为服务配置。 '位置:“未知位置” 类型:错误 消息:“ http:重复消息字段'google.protobuf.struct.fields'通过消息'uploadfilerequest'所引用的'无法映射为http参数。” 位置:“未知位置” 类型:错误 消息:“ http:循环消息字段'google.protobuf.struct.fieldsentry.value'通过消息'uploadfilerequest'方法'方法'方法'方法1.xxxxxxxx.uploadfile'无法映射为HTTP参数。
我使用不同的API配置和后端验证了GCLOUD命令。
配置本身看起来不错,即使用Swagger Editor进行验证,GCLOUD仍然不接受。 如何通过API网关定义上传文件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按照 file uplota类型:文件用于文件上传参数,
类型:String
应该使用。我尝试了配置随着参数的更改,它用Swagger编辑器结果验证为在这里。As per file upload Endpoints does not accept the
type: file
for file upload parameters,type: string
should be used instead.And I tried config with changed parameters and it validates with Swagger editor results are here.使用SwaggerHub和OpenAPI 2规格,这就是我将此文件上传工作的方式。让我知道您是否有任何疑问。这是用YAML而不是JSON规格编写的。它花了一些阅读和一些实验,但这是GCLOUD文档: htttps:htttps:// cloud。 google.com/storage/docs/uploading-objects
以及SwaggerHub信息:
它确实接受类型:formdata请求中的文件。
With SwaggerHub and OpenAPI 2 spec, this is how I got this file upload to work. Let me know if you have any questions. This is written in YAML as opposed to JSON spec. It took some reading and some experimentation, but here's the Gcloud documentation: https://cloud.google.com/storage/docs/uploading-objects
And the SwaggerHub info as well: https://swagger.io/docs/specification/2-0/file-upload/
It DOES accept type: file in the formData request.