wiremock / wiremock

A tool for mocking HTTP services
https://wiremock.org/
Apache License 2.0
6.31k stars 1.42k forks source link

FileItemPartAdapter returning multipart's field name instead of a filename #2750

Open KamilZielinski opened 3 months ago

KamilZielinski commented 3 months ago

Proposal

The FileItemPartAdapter's method getName() returns a multipart form's field name instead of the name of the file itself.

The method mentioned above looks like this:

  @Override
  public String getName() {
    return fileItem.getFieldName();
  }

The documentation from apache commons describing this method:

/**
     * Returns the name of the field in the multipart form corresponding to
     * this file item.
     * ...
     */
    String getFieldName();

My usage case where I expect list of files (single file in this case) under files key

- "files"
| - ("test1.txt", content, headers)

I'm trying to access the file (part) and get its name.

What I'm getting

part.getName() returns a string: "files"

What I was expecting

part.getName() returns a string: "test1.txt"

I'm not sure if my expectation is correct, but I thought it would return the filename using the getName() method from apache commons library (docs down below) because all other methods are used to describe the object (e.g. getBody(), getHeaders()):

/**
     * Returns the original filename in the client's filesystem, as provided by
     * the browser (or other client software). In most cases, this will be the
     * base file name, without path information. However, some clients, such as
     * the Opera browser, do include path information.
     * ...
     */
    String getName();

I believe it might be a bug but I can be just wrong as well :smile:

Reproduction steps

No reproduction in this case as this is rather a question/concern about the API.

References

No response