问题描述
/tasks/{id}/documents/files/data:
post:
tags:
- task-documents
summary: Upload document
description: Upload document
operationId: uploadDocument
parameters:
- name: id
in: path
description: ID
required: true
schema:
type: string
requestBody:
content:
multipart/form-data:
schema:
required:
- json
- upfile
type: object
properties:
upfile:
type: string
description: Document Content InputStream
format: binary
json:
description: Document Metadata
$ref: "#/components/schemas/UploadRequest"
required: true
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Document'
401:
description: Unauthorized
content: {}
500:
description: Internal Server Error
content: {}
components:
schemas:
UploadRequest:
type: object
properties:
documentName:
type: string
description: File Name of Document
contentType:
type: string
description: Mime type of document file
description:
type: string
description: Description for document
required:
- contentType
我的 build.gradle 文件具有以下生成代码的条目。
// Swagger
compile "io.swagger.codegen.v3:swagger-codegen:${versions.swaggerCodegenVersion}"
swaggerCodegen "io.swagger.codegen.v3:swagger-codegen-cli:${versions.swaggerCodegenVersion}"
implementation "io.swagger:swagger-annotations:${versions.swaggerVersion}"
implementation group: 'io.swagger.codegen.v3',name: 'swagger-codegen-generators',version: '1.0.23'
swagger-codegen-v3 在我的 API 类中生成以下方法。
@POST
@Path("/{id}/documents/files/data")
@Consumes({ "multipart/form-data" })
@Produces({ "application/json" })
@ApiOperation(value = "Upload document",notes = "Upload document",response = Document.class,authorizations = {
@Authorization(value = "cut_basic"),@Authorization(value = "cut_oauth",scopes = {
@AuthorizationScope(scope = "",description = "")})},tags={ "documents",})
@ApiResponses(value = {
@ApiResponse(code = 200,message = "successful operation",response = Document.class),@ApiResponse(code = 401,message = "Unauthorized",@ApiResponse(code = 500,message = "Internal Server Error",response = Document.class)})
public Response uploadDocument(@Context UriInfo uriInfo,@FormDataParam("upfile") InputStream upfileInputStream,@FormDataParam("upfile") FormDataContentdisposition upfileDetail,@Parameter(description = "",required=true)@FormDataParam("json") UploadRequest json,@Parameter(description = "ID",required=true) @PathParam("id") String id,@Context SecurityContext securityContext) throws NotFoundException {
LOG.debug("Upload document : Upload document");
LOG.debug( "upfile :" + upfile + "," + "json :" + json + "," + "id :" + id + "," + ";");
delegate.setProviders(providers);
Response response = delegate.uploadDocument(uriInfo,upfileInputStream,upfileDetail,json,id,securityContext);
LOG.debug("Exiting - uploadDocument");
return response;
}
当我尝试点击请求时,尽管我以以下格式传递值,但我总是将 UploadRequest 对象设为 null。但是,我正确填充了 FormDataContentdisposition 和 InputStream。
--Boundary_123456789_123456789
Content_transfer-encoding: binary
Content-disposition: form-data; name="upfile"; filename="test.txt"
I am a test file!!!
--Boundary_123456789_123456789
Content-disposition: form-data; name="json"
Content-Type: application/json
{
"documentName": "string","contentType": "string","description": "string"
}
--Boundary_123456789_123456789--
不太清楚那里发生了什么。有人可以帮助我解释为什么 json 对象为空。我在这里遗漏了什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)