Uploading a file or document in Postman

I am not able to upload a document or file in postman. I tried in form-data to upload the file. But its not working.

Also i tried to pull the file through raw body. But both im not able to proceed. I need some key value or exact key word to continue. One of the Error is as below.

{
    "error": {
        "code": "InvalidRequest",
        "message": "Invalid Request.",
        "innererror": {
            "code": "EmptyRequest",
            "message": "Request body must be present."
        }
    }
}

If Anyone can guide me it will be helpful.

Hey @dhans12 :wave:

Welcome to the Postman Community! :postman:

Are you using a public API? Do you have any documentation that you could share?

I’m not sure about the implementation of the API or how you’re supposed to use files with it. :frowning:

Could you provide some more information, please?

Hi Danny,
As of not im not using it as public as im a beginner to Postman. Im trying Text analytics using Azure. In this context i would like to upload some files to check.
What should be the key i should give as per the API Documentation?


If i run this with content type as application json. The error is as follows

If i change the content type as multipart form-data then the error is
“Unsupported content type ‘multipart/form-data’”
Can you help me with this information or you need more details?

Which documentation are you following? :smiley:

I would need to see this to be able to provide you with a suggestion.

Hi Danny,
View documentation in Postman | Postman Learning Center- I refer this one.

I think Danny meant the documentation for the API.

For the Azure Text Analytics. (Rather than Postman documentation).

This will be down to what the API accepts. 4xx status codes mean the request is not in the correct format.

Pretty sure you wouldn’t upload a JSON file using form-data.

When sending binary files using form data, you need select “file” as the key. (which you appear to be missing).

For example…

image

However, this is all guess work without seeing the API documentation. Good documentation usually provides example request\responses. A lot of the Azure API’s have Postman collections that you can download that all you need to do is plug your credentials into the appropriate environment variables.

1 Like

Hi
oh sorry i misunderstood.

This is the documentation im following.
I have already tried the way which you shared but not posted the screenshots here. Also im not using Public API.
Hope someone can guide me.
Thanks in advance.

The API documentation is here.

Text Analysis Runtime - REST API (Azure Cognitive Services - Language) | Microsoft Learn

Which of the four operations are you trying to get working?

The submit job request?

There are examples of how to consume the API.

{
  "displayName": "Extracting Location & US Region",
  "analysisInput": {
    "documents": [
      {
        "id": "1",
        "language": "en",
        "text": "I had a wonderful trip to Seattle last week."
      },
      {
        "id": "2",
        "language": "en",
        "text": "I'm flying to NYC tomorrow. See you there."
      }
    ]
  },
  "tasks": [
    {
      "kind": "EntityRecognition",
      "taskName": "Recognize Entities",
      "parameters": {
        "modelVersion": "latest"
      }
    },
    {
      "kind": "CustomEntityRecognition",
      "taskName": "Recognize US Regions",
      "parameters": {
        "projectName": "MyProject",
        "deploymentName": "MyDeployment"
      }
    }
  ]
}

This doesn’t appear to be uploading a file or document in the traditional sense.

In this circumstance it appears that the “document” is part of the JSON that you put in the body (and the text appears to be a string).

Hi Mike,
Currently im looking into Analyse Text.
I have worked on giving the text directly in the body and it worked successfully. But now instead of giving text, I want to upload a file or a document. Here im getting one or the other error.

Where does it say in those docs that it supports that method?

We can upload a file using form-data or binary in postman. Thats my understanding. Don’t know its correct or not.

You could potentially use the collection runner and a data file which contains the JSON for the document element.

You can then parameterise that in the JSON body using a variable.

Looping through a Data File in the Postman Collection Runner | Postman Blog

Only if the API accepts that. This isn’t a Postman function. Form data and binary uploads are part of the http and web standards and your API will either support that or it won’t.

There is no-where in the API documentation that I could find that allows this for this type of file upload.

Have a look at the examples.

None of them are showing binary data, or form-data for that matter. They are all raw\JSON requests.

OK Mike. Thank you so much. I will get back to you soon once i go through all the documentations which you shared.

No problem.

It appears that this API requires a raw\JSON body and the documents are contained in an array in that JSON body.

You can set the body to read that array from a variable. (Which can be read from a data file using the collection runner).

For example…

{
  "displayName": "Extracting Location & US Region",
  "analysisInput": {
    "documents": {{documents}}
  },
  "tasks": [
    {
      "kind": "EntityRecognition",
      "taskName": "Recognize Entities",
      "parameters": {
        "modelVersion": "latest"
      }
    },
    {
      "kind": "CustomEntityRecognition",
      "taskName": "Recognize US Regions",
      "parameters": {
        "projectName": "MyProject",
        "deploymentName": "MyDeployment"
      }
    }
  ]
}

You could take the same approach for the tasks array if needed.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.