Skip to content

Mark serialized objects in multipart/form-data as application/json [implemented] #1049

@mstieranka

Description

@mstieranka

Currently, when an object is sent using the multipart/form-data content type, none of the individual parts have a set content type.

This, however, can be an issue in applications where the server doesn't have a suitable default for form data parts (as is the case in Spring, which considers all parts without a type to be application/octet-stream). When no content type is set and a JSON string representing an object is sent, its content cannot then be deserialized as the server doesn't know that the received content is of the application/json type.

It would therefore be great if this library would tag all parts that have been serialized from an object to a JSON string as application/json. The code that this relates to is shown below:

const process = (key: string, value: any) => {
if (isString(value) || isBlob(value)) {
formData.append(key, value);
} else {
formData.append(key, JSON.stringify(value));
}
};

It's also important to mention that because of the aforementioned issue with Spring, I have already created a forked version of this library that implements this mechanism, but I have not submitted a PR yet, since I'm not sure if this is desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions