Contributing

What is the Content-Type for file upload?

What is the Content-Type for file upload?

By default CURL always adds Content-Type: application/x-www-form-urlencoded , what makes the API server think, that the body contains parameters. So, to upload files as the body always specify the Content-Type, e.g. application/octet-stream .

What is Content-Type in post request?

The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending). It also needs to have a MIME type of its parsed value (ignoring parameters) of either application/x-www-form-urlencoded , multipart/form-data , or text/plain .

How do I upload a file to REST API?

Send the file first in a multipart/form-data POST, and return an ID to the client. The client then sends the metadata with the ID, and the server re-associates the file and the metadata. Send the metadata first, and return an ID to the client.

What is the Content-Type of a GET request?

It means that the Content-Type HTTP header should be set only for PUT and POST requests. GET requests can have “Accept” headers, which say which types of content the client understands. The server can then use that to decide which content type to send back.

What are the MIME content types?

Common MIME types

Extension Kind of document MIME Type
.arc Archive document (multiple files embedded) application/x-freearc
.avi AVI: Audio Video Interleave video/x-msvideo
.azw Amazon Kindle eBook format application/vnd.amazon.ebook
.bin Any kind of binary data application/octet-stream

How does HTTP file upload work in Stack Overflow?

You can upload like this: If you don’t (want to) use forms and you are only interested in uploading one single file this is the easiest way to include your file in the request.

How to describe a file upload in OpenAPI?

In OpenAPI 3.0, you can describe files uploaded directly with the request content and files uploaded with multipart requests. Use the requestBody keyword to describe the request payload containing a file.

How to send a file as only content?

The file is only a part of the data sent in the request, hence the multipart/form-data Content-Type header. If you want to send the file as the only content then you can directly add it as the request body and you set the Content-Type header to the MIME type of the file you are sending. The file name can be added in the Content-Disposition header.

How does a multipart file upload work?

As with other multipart types, the parts are delimited with a boundary delimiter, constructed using CRLF, “–“, and the value of the “boundary” parameter. every field gets some sub headers before its data: Content-Disposition: form-data;, the field name, the filename, followed by the data.