usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
21.79k stars 1.03k forks source link

Multi-part requests: user should be able to set content-type for each part in a multi-part request. #1602

Open ash-eng-spin opened 4 months ago

ash-eng-spin commented 4 months ago

When setting up a multipart request, Bruno automatically selects the content-type of the file part. The auto-assigned content-type is not always the desired content-type of the API spec, therefore our request will always result in a 400 Bad Request, because the content-type is wrong.

Please allow a way for the user to set the content type for a multi-part request part. File or text

Text/Param: user should be able to set because this could be blank, application/json, application/xml, text/plain or many other things. Files: user should be able to set because this could be blank, application/pdf, application/octet-stream, application/vnd.ms-excel, text/csv or many other things.

Example: Multipart Form Data: PDF file content-type automatically set. No manual way for user to set content-type for a file. Why is this a problem: API spec for the pdf file wants "application/octet-stream" for the content-type. Bruno automatically sets the content-type to "application/pdf". No way to manually set the content-type. Results in 400 bad request because content-type does not match API spec and there is no way to change in Bruno.

image

This appears to align with your plans to update the Bru Lang Schema https://github.com/usebruno/bruno/issues/1502 but I want to make sure the user can set the content-type in the UI for params and files.

Versions

v1.9.0

Steps to reproduce 1

  1. Create POST request
  2. Go to Body
  3. Select Multipart Form
  4. Click Add Param
  5. Enter key and value <---User cannot change content-type of the file

Steps to reproduce 2

  1. Create POST request
  2. Go to Body
  3. Select Multipart Form
  4. Click Add File
  5. Enter key and select file<---User cannot change content-type of the file

For reference this is how it works in Postman: image

busy-panda commented 2 months ago

Hi,

We have the same problem indeed especially for parameters in JSON format. I sent a PR so that it detects when the parameter is in JSON format, and add Content-Type: application/json in this case.

ddasol commented 2 months ago

We are facing the same issue. This is the single feature missing so we can fully migrate to Bruno. We need to send a file and a json in the same request. It seems like @busy-panda 's PR could do the trick while we wait for a feature as suggested by @ash-eng-spin .

ngujjari27 commented 2 months ago

We had the same issue. Hope the change provided by @busy-panda will be approved quickly.

busy-panda commented 2 months ago

Sorry I closed my PR because I prefer to fully implement as suggested by @ash-eng-spin, so I will add a column "Content-Type".

That will probably take more time.

busy-panda commented 2 months ago

The enhancement is fully implemented and the PR was created: https://github.com/usebruno/bruno/pull/2121

fskexp commented 2 months ago

I had a case where I needed to send in a multi-part form a file item and a JSON item. At first, I provided the JSON as a "Param" item. No content-type was automatically set for this form entry, so the request was rejected by my server. Work-around: I passed the JSON as a JSON file and Bruno automatically set the content-type, so my server accepted the request. I agree that being able to manually define the content-type of each item would be better.

ddasol commented 2 months ago

I had a case where I needed to send in a multi-part form a file item and a JSON item. At first, I provided the JSON as a "Param" item. No content-type was automatically set for this form entry, so the request was rejected by my server. Work-around: I passed the JSON as a JSON file and Bruno automatically set the content-type, so my server accepted the request. I agree that being able to manually define the content-type of each item would be better.

Thank you for sharing. I just tested and it worked for me as well.

Good option until we can manually/individually set the content-type.