Uploading files using multipart/form-data in swagger-node-express

2,551 views
Skip to first unread message

Paul Nebel

unread,
Sep 25, 2014, 6:01:49 AM9/25/14
to swagger-sw...@googlegroups.com
I've seen several posts describing how to upload files using swagger using multipart/form-data but have had no luck when using swagger-node-express v2.0.3.

My resource defines the relevant parameter as follows:
{
  "name": "File",
  "description": "The file to upload.",
  "paramType": "body",
  "required": true,
  "allowMultiple": true,
  "dataType": "file"
}

I've set the resource to consume 'multipart/form-data' and am sending an additional parameter in the request.  The file upload fails every time with a 'boundary not set' error (note that it fails with this error whether or not I include the additional parameter).  

When examining network traffic I can see that the UI isn't even sending the file data in the request.

I've tried the pet store file-upload example online and simply get a 'file not found' message.  

Is multipart file upload actually supported in swagger-node-express?  If so, how am I supposed to use it?  I've followed all the examples I can find but am not having any luck.

Thanks.

Ron

unread,
Sep 25, 2014, 9:08:24 AM9/25/14
to swagger-sw...@googlegroups.com
Hi Paul,

I have no experience with node, but the parameter definition as you pasted seems odd. It looks like a very old version of the Swagger specification.
It should look like this:

{
  "name": "File",
  "description": "The file to upload.",
  "paramType": "form",
  "required": true,
  "allowMultiple": true,
  "type": "File"
}

Note that the paramType is "form", "dataType" has changed to "type" and "file" has been capitalized.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul Nebel

unread,
Sep 25, 2014, 9:41:34 AM9/25/14
to swagger-sw...@googlegroups.com
Hi Ron

Thanks very much for your reply.

I've made the suggested changes but I'm afraid I get the same issue: "content-type missing boundary: null".  In stepping through the swagger.js I had noticed that I got a bit further by setting paramType to 'form' but I still can't get beyond the missing boundary.  Unfortunately there appears to be very little authoritative information regarding file uploads in Swagger on the interweb (even the live example doesn't work!) so my current solution is gathered from the scraps of information I could find - some of it contradictory.

Ron

unread,
Sep 25, 2014, 9:46:42 AM9/25/14
to swagger-sw...@googlegroups.com
Actually, the live sample works. I've just tested it and uploaded a file with no issue.

Can you possibly share the full swagger json you're getting from your application? Perhaps I'll find some other issue.
If you can't share it publicly, feel free to send it to me directly.

--
Reply all
Reply to author
Forward
0 new messages