Kong / Kong/insomnia

Insomnia does not include part's content-type in curl command for multipart request

Open
#4,334 1 comment 0 reactions 0 assignees View on GitHub
B-bug S-verified
Dominant language
TypeScript
Stars
40k
Forks
2.4k
Avg merge
2d 13h
Merged PRs (30d)
61

Description

### Expected Behavior

curl command to include `;type=application/json` for metadata part

### Actual Behavior

The `;type=application/json` is missing and generated curl does not send a valid request.
The server responds:
> Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported]

### Reproduction Steps

0. Consider the following simple http handler (since I am a Java developer, the example is based on Spring Boot), the `App.groovy`:
```groovy
import groovy.transform.ToString
import org.springframework.web.multipart.MultipartFile;

@RestController
class WebApplication {
@PostMapping(path = "/upload-file", consumes = "multipart/form-data")
String home(@RequestPart MultipartFile file, @RequestPart FileUploadMetadata metadata) {
println(metadata)
}
}

@ToString
class FileUploadMetadata {
String description
}
```

It expects multipart POST request of 2 parts:
- the `file` itself
- and some json-formatted `metadata` with `description` field (as an example)

1. run the server app with `spring run App.groovy`. PS the easiest way to get `spring` command is to install [SDKMAN](https://sdkman.io/) and then install both Java and Spring Boot: `sdk i java`, `sdk i springboot`
2. Create a POST multipart request with Insomnia for `http://localhost:8080/upload-file`, add some `file` and add `metadata` with the following content:
```json
{
"description": "Some description for my file"
}
```
3. Set JSON type for `metadata` part

Image

![image](https://user-images.githubusercontent.com/1719646/147881161-8d5c913c-4f28-4317-9100-fdb99795a078.png)

3. Execute the request with Insomnia, it works and the return code is 200
4. Copy and try to execute the curl command, the result will be:
```shell
curl --request POST \
--url http://localhost:8080/upload-file \
--header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
--form 'metadata={
"description": "Some description for my file"
}' \
--form file=@/Users/user/Documents/file.md
```

and it does not work, because the `;type=application/json` is missing for `metadata`

### Is there an existing issue for this?

- [X] I have searched the [issue tracker](https://www.github.com/Kong/insomnia/issues) for this problem.

### Additional Information

_No response_

### Insomnia Version

2021.7.2

### What operating system are you using?

macOS

### Operating System Version

Monterey 12.1

### Installation method

brew install insomnia

### Last Known Working Insomnia version

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by locating the code that generates Insomnia's curl command and serializes multipart form parts. Reproduce the described request with a JSON metadata part, then verify that the generated curl command includes the part's application/json content type and sends a valid request.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.