file upload schema error 400
See original GitHub issueHi, when i define the schema consumer in endpoint /upload to ‘multipart/form-data’ for uploading file i dont know wich is the schema structure body for passing the base64 string or the file that i need to upload.
If y define the schema:
schema: {
description: 'Upload file',
tags: ['Info'],
consumes: [ 'multipart/form-data' ],
summary: 'Upload the file to the server',
body: {
type: 'object',
properties: {
file: {type: 'string'}
}
},
response: {
200: {
description: 'Succesful response',
type: 'boolean'
}
}
}
when i send the post get the error:
{
"statusCode": 400,
"error": "Bad Request",
"message": "body should be object"
}
I fetch in the dynamic.js code looking for the solution but i dont get with it.
Can you help me?
PD: Im sorry if this is not the place for this kind of issues.
Thx
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:47 (19 by maintainers)
Top Results From Across the Web
Upload REST API shows 400 bad request - Alfresco Hub
Returning 400 means that the request was malformed. In other words, the data stream sent by the client to the server didn't follow...
Read more >Getting HTTP 400 error while uploading xml file - REST
I am using AS3 command file.upload(). Upload progress shows uploading till 100% but file is not uploaded on the server. I also tried...
Read more >400 Bad Request when trying to send large file to service ...
Hi All,. I am trying to send the large file (approx 1.5GB) to the WCF service for upload using basic http streaming.
Read more >Getting the infamous 400 error from graphql when uploading a ...
So the problem is with Apollo's internal implementation of graphql-upload. If you are autogenerating your schema I would advise you to ...
Read more >How to Fix a 400 Bad Request Error [Causes and Fixes]
The HTTP error 400 can be caused by the file you're uploading being too large. That's usually because there's a file size limit...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found another workaround based on @SkeLLLa’s suggestion, where I add a small ajv plugin to fastify, which I believe might be a little bit less intrusive?
Below is a fully functioning example:
Here’s another workaround.
First of all as it was mentioned above we should add custom
binary
format:Afterwards in your routes we should do some hack that will allow to pass ajv validation for string type. So we need
preValidation
hook where we’ll replace what’s come from user with some string, so ajv will validate it and hide original file inside non-enumerable property.