getsandbox / worker-cli

Sandbox Worker is the core processing component of the Sandbox product
https://getsandbox.com
230 stars 62 forks source link

How to read Content-Type: multipart/form-data; ? #28

Closed abhijeetahuja closed 4 years ago

abhijeetahuja commented 7 years ago

My client is sending the data in post request as Content-Type: multipart/form-data; boundary=----WebKitFormBoundary0rrbbU838w7gACJi, how can I access that in my code. I've tried req.body['user_id'], but it doesn't work. I even tried to get an idea from the case study but that didn't help either. It works for content-type: application/x-www-form-urlencoded

From the sandbox console:

Request Body

------WebKitFormBoundary0rrbbU838w7gACJi
Content-Disposition: form-data; name="file_id"

214151585698
------WebKitFormBoundary0rrbbU838w7gACJi
Content-Disposition: form-data; name="user_id"

2344577474
------WebKitFormBoundary0rrbbU838w7gACJi--
tylergannon commented 6 years ago

Sorry to necrobump, but I am new to getsandbox and am having this issue as well. @abhijeetahuja did you come up with anything?

abhijeetahuja commented 6 years ago

@tylergannon I ended up using Mockable.io for this particular use case.

nhoughto commented 6 years ago

Hmm not sure how i missed this, normally we try and comment / close off any issues sorry for the many month delay.

At the moment we dont' do any special processing on multipart form-data types, obviously you can cut up the body yourself via req.body.split(..) etc, but that kinda sucks. I'll put something on the backlog to process it properly. I presume the ideal behaviour would be accessing the form data via its name/key? req.body.user_id? This would work in cases where the form part is non-binary, does that suit your usecase?

nhoughto commented 4 years ago

Fixed