Closed AlexGorodilov closed 2 years ago
can use format your code with markdown
Close up for a long time is not active Issue
Sorry for reopening but I can't see why I get this error
static uploadFile(
params: {
/** */
id: string;
/** */
type: string;
/** */
file: any;
} = {} as any,
options: IRequestOptions = {}
): Promise<GedFileDto> {
return new Promise((resolve, reject) => {
let url = basePath + '/ged/files/{id}/upload';
url = url.replace('{id}', params['id'] + '');
const configs: IRequestConfig = getConfigs('post', 'multipart/form-data', url, options);
configs.params = { type: params['type'] };
let data = null;
data = new FormData();
if (params['file']) {
if (Object.prototype.toString.call(params['file']) === '[object Array]') {
for (const item of params['file']) {
data.append('file', item as any);
}
} else {
data.append('file', params['file'] as any);
}
}
configs.data = data;
axios(configs, resolve, reject);
});
it should just this
let data = new FormData();
any details?
Yes sorry,
/ged/files/{id}/upload: {
post: {
operationId: "uploadFile",
parameters: [
{
name: "id",
required: true,
in: "path",
schema: { type: "string" }
},
{
name: "type",
required: true,
in: "query",
schema: { type: "string" }
}
],
requestBody: {
required: true,
content: {
multipart/form-data: {
schema: {
type: "object",
properties: { file: { type: "string", format: "binary" } }
}
}
}
},
responses: {
201: {
description: "",
content: {
application/json: { schema: { $ref: "#/components/schemas/GedFileDto" } }
}
}
},
tags: [
"ged"
]
}
}
i will try it.
@MinaroShikuchi fix in v0.12.9
It works great. Thanks a lot !
Hello.
When I use multipart/form-data.
Such code is generated. And compiller type script show error.
export class FileService { /**
Загрузка файлов на сервер */ static uploadFile( params: { /* / uploadedFile: any; } = {} as any, options: IRequestOptions = {} ): Promise {
return new Promise((resolve, reject) => {
let url = '/api/File/UploadFile';
const configs: IRequestConfig = getConfigs('post', 'multipart/form-data', url, options);
let data = null; data = new FormData(); if (params['uploadedFile']) { data.append('uploadedFile', params['uploadedFile'] as any); }
configs.data = data; axios(configs, resolve, reject); }); } }
Type 'FormData' is not assignable to type 'null'
JSON file is next
"/api/File/UploadFile": { "post": { "tags": [ "File" ], "summary": "Загрузка файлов на сервер", "requestBody": { "content": { "multipart/form-data": { "schema": { "type": "object", "properties": { "uploadedFile": { "type": "string", "description": "файл", "format": "binary", "nullable": true } } }, "encoding": { "uploadedFile": { "style": "form" } } } } }, "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "type": "integer", "format": "int32" } } } } } } },