Content-type specification for posting image data via http communication

Asked 1 years ago, Updated 1 years ago, 348 views

If you look at how to post image data via http communication, every article says Content-Type: multipart/form-data.(Or you can encode the image binary data in base64 and include it in json etc.)

In my perception, multipart/form-data is a perception that I specify when I send multiple types of data at once, but as far as I've looked, multipart/form-data is treated as if it's necessary to send images.

Is it actually necessary to specify multipart/form-data to send images?
If it is a single image, I wonder if it is possible to send binary data of the image using the content-type as image/png.

api http image https

2023-01-13 22:08

1 Answers

If you want to send a file as form data, not just an image, you must specify multipart/form-data because it also contains non-file data.All but files are text data, but files are binary data.

Submit Form Data - Learn Web Development | MDN

Since the data is divided into several parts and each file and string data is included in the form body, set the enctype value to multipart/form-data.

This does not apply to uploading files in the program.

Using Files from a Web Application - Web API | MDN

The upload MIME type is set by calling the XMLHttpRequest function overrideMimeType().In this case, you are using a typical MIME type.You may not need to configure the MIME type for some purposes.


2023-01-15 00:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.