-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload binary files via multipart/form-data
from REST API Explorer
#2666
Comments
found out that OpenAPI 3.0 requestBody spec needed for recognising as upload requires properties, with format: 'binary'. options = { unknownFormats: ["binary"]}
const ajv = new AJV(Object.assign({}, {
allErrors: true,
}, options)); After adding this, swagger-ui works as expected, with upload button and file uploaded no prob. But it seems , there is no way to set the AJV options. Only he following formats are supported for string validation with AJV "format" keyword: date: full-date according to RFC3339. Possible to add way to enter the Current OpenApi Data Types to default options?
|
multipart/form-data
from REST API Explorer
Thank you @stoffason for reporting the issue and investigating further information. We don't have first-class support for file uploads yet, this feature is tracked by #1873. Let's keep this issue open as a place where to investigate and discuss different options for enabling REST API Explorer to upload files to LB4 applications. The request-body schema you posted in your last comments seems reasonable to me. @requestBody({
description: 'multipart/form-data value.',
required: true,
content: {
'multipart/form-data': {
'x-parser': 'stream',
schema: {
type: 'object',
properties: {
file: {
type: 'string',
format: 'binary'
}
}
}
}
}
})
This looks like a bug in our validation layer. IMO, we should skip validation of request bodies that are parsed as a I think we should to the same for Would you like to contribute such change(s) yourself? You can find the code parsing request bodies in packages/rest/src/body-parsers/body-parser.ts. See https://loopback.io/doc/en/contrib/code-contrib-lb4.html and https://loopback.io/doc/en/lb4/submitting_a_pr.html to get started. |
As a temporary workaround, you can leverage the recently-landed #2992 to configure AJV with |
The following works for me: this.bind(RestBindings.REQUEST_BODY_PARSER_OPTIONS).to({
validation: {unknownFormats: ['binary']},
}); |
I'm blocked by swagger-api/swagger-ui#4600 |
See a working example at #4801 |
Description / Steps to reproduce / Feature proposal
Unable to use local swagger-ui to upload files (Button missing).
Loopback requestBody does not accept "format: binary" used by openAPI to determine that the input field is for file upload.
Current Behavior
When using upload controller from example, the swagger-ui upload button does not appear and only shows a text box (no Upload button)
However if following openAPI spec, the button shows, but on submission of the file, errors occur unknown format "binary" is used in schema at path "#"
Expected Behavior
Either code should work or?
See Reporting Issues for more tips on writing good issues
From example - Button not showing
But change the request body to:
the choose file button appears, but on submission I get the error...
Unhandled error in POST /image: 500 Error: unknown format "binary" is used in schema at path "#/properties/file"
A bit lost here... thanks!
The text was updated successfully, but these errors were encountered: