File upload with Node
See original GitHub issueI’m having a hard time figuring out how to create a file upload example using our swagger docs. It works fine with our Swagger UI.
The API declaration basically looks like:
{
"apiVersion": "3",
"swaggerVersion": "1.2",
"basePath": "/3",
"resourcePath": "/files.{format}",
"apis": [
{
"path": "/files.{format}",
"operations": [
{
"method": "POST",
"summary": "Upload a JPG file (up to 100MB)",
"nickname": "uploadFile",
"parameters": [
{
"name": "File",
"description": "The file",
"paramType": "body",
"required": true,
"type": "file"
}
],
"type": "File",
"responseMessages": [
{
"code": 201,
"message": "Request succeeded"
}
]
},
In the swagger js client the method ends up being as shown here:
swagger.apis.files.uploadFile(...)
It’s just unclear to me what to pass in as the arguments. I imagine is some combination of a the output of fs.readFileSync() and setting a requestContentType header to multipart/form-data, but so far I haven’t been able to get the data sent to the server.
Any ideas? I haven’t seen any examples of this yet through extensive searching.
Thanks! It’s the missing link in our recently publishes Swagger docs.
Issue Analytics
- State:
- Created 9 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
File uploading in Node.js - GeeksforGeeks
Introduction: File uploading means a user from client machine requests to upload file to the server. For example, users can upload images, ...
Read more >Node.js file upload example with Ajax and JavaScript
Step-by-step Node.js file upload example · Ensure Node. · Create a file named upload. · Add FileSystem (fs) and Formidable library dependencies ...
Read more >How to Handle File Uploads from Node.js to Express - Twilio
Learn how to upload files by posting multipart/form-data from Node.js to Express with the help of the FormData and Multer libraries.
Read more >Multer: Easily upload files with Node.js and Express
Multer is a Node.js middleware for handling multipart/form-data that makes the otherwise painstaking process of uploading files ...
Read more >How to Implement a File Upload Server with Node.js
We can use the HTML form to upload files, and in the Node.js server, we can use the busboy package to parse incoming...
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’m having problems to implement file uploads in node js.
I have the following swagger 2.0:
And I am trying to call this using the following code:
The request is created to target operation, but the expected parameters (name and file) are both being received as undefined. Not is being sent to the server.
I also tried to change the
createReadStream
call tofs.readFileSync(fileName)
, but the problem remains.Am I missing something? Is it the correct way to call this? I could not find any documentation nether a test case. The links to test cases above are broken.
Thanks in advance.
@thiagobustamante Were you able to fix your issue? I’m experiencing the same problem, and from reading the source code, it’s not possible to pass a buffer for a formdata file upload if you’re targeting a swagger 2.0 spec? https://github.com/swagger-api/swagger-js/blob/ba6c94912bb13e7fb2cdc6bc88b348c353a789c8/src/execute/oas3/build-request.js#L71
Edit: looks like the file can be passed in via
fs.createReadStream($FILE_PATH)