lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.56k stars 499 forks source link

Fileupload using octet-stream #1080

Open dderevjanik opened 3 years ago

dderevjanik commented 3 years ago

Sorting

Expected Behavior

Right now, is not possible to upload file using octet-stream, only by using @UploadedFile which is multipart-formdata. Would be great to have option to upload files using octet-stream (for big file upload).

requestBody:
  content:
    application/octet-stream:
      schema:
        type: string
        format: binary

could be generated from this:

    @Post("/upload")
    async streamUpload(@Request() req: Req, @Body() stream: Readable): Promise<void> {
       return new Promise((resolve, reject) => {
          stream.on("data", (chunk) => console.log(chunk));
          stream.on("error", (chunk) => reject());
          stream.on("end", (chunk) => resolve());
       });
    }

TSOA could automatically detects that requesting using @Body() body: Readable should be octet-stream.

Current Behavior

Currently, TSOA will generate (from code above)

"requestBody": {
    "required": true,
    "content": {
        "application/json": {   // this should be "application/octet-stream"
            "schema": {
                "type": "string", 
                "format": "byte"
            }
        }
    }
}
falk-stefan commented 7 months ago

+1