Huachao / vscode-restclient

REST Client Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=humao.rest-client
MIT License
5.32k stars 446 forks source link

Multipart file request for nonexistent file path shows 19 bytes length on server - why? #1318

Open raffian opened 3 weeks ago

raffian commented 3 weeks ago
0.25.1 - RESTClient
1.95.0 - VSCode
WindowsNT/10 x64 10.0.10945

I don't know if this is a problem with the extension or Java/Spring/openapi custom server code handling requests but here goes.

We use this multipart request for uploading PDF files from a client machine; works great. All parts in the request are required for POST - nothing is optional.

POST http://localhost:8080/upload-test HTTP/1.1
Content-Type: multipart/form-data; boundary="PARTBOUNDARY"

--PARTBOUNDARY
Content-Disposition: form-data; name="testcode"
Content-Type: text/plain

UPLOAD_CODE_1
--PARTBOUNDARY
Content-Disposition: form-data; name="context"
Content-Type: application/json

{"id": "123"}
--PARTBOUNDARY
Content-Disposition: form-data; name="file"; filename="notexist.pdf"
Content-Type: application/pdf

< C:/files/temp/notexist.pdf
--PARTBOUNDARY--

Problem

If we change the file path to a nonexistent file, the request is still sent and does not generate warning or error. Upon receiving the request on the server, we check the file part content length to be 19 bytes. Very strange - where does 19 bytes come from if the file part in the request was for nonexistent file? How does the extension prepare and send multipart request when file path is invalid?

    @Override
    public ResponseEntity<UploadApiResponse> uploadStuff( 
        @Valid String testcode,
        MultipartFile file,
        @Valid RequestCtx context, ) {

         if(file != null){
             log.info("file size: " + file.getSize());    //file size = 19 bytes for nonexistent file uploaded in request?