guettli guettli - 3 months ago 13
HTTP Question

Which http request method for web API which receives big files

Which http request method is suitable to receive big files?

My use case: I want to provide a HTTP API:


  • Input: mp3 file. The whole file (not just the file name)

  • Output: List of possible music interpreter singing this song.



Since no data gets modified on the server I think
POST
and
PUT
don't fit.

AFAIK the method
GET
does not fit:


  • the mp3 file is too big for the query-string.

  • GET-requests with data in the body are new to me.



Which http request method for web API which receives big files?

Update


  • This is not an upload. The mp3 is the input, some text is the output.



Update2

Imagine you want to provide a HTTP API for
calculate_square_root()
. If you input
9
you receive
3
. Would you use the word "upload" for the number
9
? Where to draw a line between normal GET and big GET?

Answer

To send the content of a file to the server, you should use a POST request:

4.3.3. POST

The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics. For example, POST is used for the following functions (among others):

  • Providing a block of data, such as the fields entered into an HTML form, to a data-handling process; [...]

The content of the file will be sent in the payload of the request and the Content-Type of the request should be set to multipart/form-data.