Is there a way to get the file type and file size of a document/file that is being passed as request/ response body?

Not applicable

For example, I have an upload and download API. For the upload, I need to be able to get the file size and file type in the request (note that the size of the attached/selected file is needed, and not the size of json body/payload request and response). And for the download API, I also need to get the file size and type of the file to be downloaded.

0 1 2,645
1 REPLY 1

Hi @Junnes Ashley Pineda

Yes its possible. The request & response needs to be of multipart/form-data content type. The file can be passed as binary data in one parts of the multipart request/response. The Content-Disposition header parameter can be used to find the file name and from it file type. For more details refer this link

In case the multipart data has only your file content then content-length header parameter can be used to calculate the size. Else you will have to do some custom coding to extract the file content and then derive its size.