Get a filename from a form-data request body field

Hi,

To upload a file, my API needs a POST request with the following fields filled out correctly:

  • file_name: the name of the file once in the repository,
  • file_content: the binary content of the file.

This is how I write it in cURL :
curl https://{{url_api}}/entite/{{entity}}/document/{{document_id}}/file/fichier_metadata -X POST -F file_name=metadata.json -F file_content=@"files\metadata.json"

I was able to do the same in Postman using a form-data body:
image

It works perfectly fine. However, is there any way to avoid manually entering the “file_name” field value? I’d like Postman to fill this field with the name of the file I’ve selected in the “file_content” field.

We’re closing out older posts with no replies to keep the community organized. If you still need help with this issue, feel free to post a new topic or reply here to reopen.

You can paste the curl command directly into the URL bar and it will create the request for you with the specified values. You could also create a local variable for the filename and write a pre-request script to populate the file_name based on the file_content name using some regex.