---
title: uploads an image
slug: docs/demo/uploads-an-image
description: Learn how to use cURL to send a POST request and upload an image for a pet with an assigned ID. This code example demonstrates how to include JSON data headers and empty form fields for metadata and the actual file, ensuring a smooth image upload process.
docTags: 
createdAt: 2022-11-25T15:11:39.000Z
---

{
  "id": "aAZI4hwWXcD8lbjDJwHva",
  "data": {
    "url": "https://petstore.swagger.io/v2/pet/{petId}/uploadImage",
    "name": "uploads an image",
    "method": "POST",
    "request": {
      "pathParameters": [
        {
          "kind": "required",
          "name": "petId",
          "type": "integer",
          "description": "ID of pet to update"
        }
      ],
      "queryParameters": [],
      "headerParameters": [],
      "bodyDataParameters": [],
      "formDataParameters": [
        {
          "kind": "optional",
          "name": "additionalMetadata",
          "type": "string",
          "description": "Additional data to pass to server"
        },
        {
          "kind": "optional",
          "name": "file",
          "type": "file",
          "description": "file to upload"
        }
      ]
    },
    "responses": [
      {
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "kind": "optional",
                "name": "code",
                "type": "integer<int32>",
                "example": 0
              },
              {
                "kind": "optional",
                "name": "type",
                "type": "string",
                "example": ""
              },
              {
                "kind": "optional",
                "name": "message",
                "type": "string",
                "example": ""
              }
            ],
            "modelRef": "#/definitions/ApiResponse",
            "customType": "ApiResponse",
            "isExpanded": true
          }
        ],
        "isExpanded": true,
        "statusCode": "200",
        "description": "successful operation",
        "jsonExample": ""
      }
    ],
    "contentType": "multipart/form-data",
    "description": "",
    "examples": {
      "languages": [
        {
          "id": "lAN466gL_Wu8TLdJYFHAc",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://petstore.swagger.io/v2/pet/{petId}/uploadImage \\\n     --header 'accept: application/json'"
        },
        {
          "id": "dbczHfPLQukUH-vPmECfn",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"multipart/form-data\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"https://petstore.swagger.io/v2/pet/{petId}/uploadImage\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "ePUkw7mae5HmUiryzez0y",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"net/http\"\n\nurl = URI(\"https://petstore.swagger.io/v2/pet/{petId}/uploadImage\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"multipart/form-data\"\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "2rkztT58vz46niFHJotqB",
          "language": "python",
          "label": "Python",
          "code": "import requests\n\nurl = \"https://petstore.swagger.io/v2/pet/{petId}/uploadImage\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'multipart/form-data'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "lAN466gL_Wu8TLdJYFHAc"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// successful operation\n{\n  \"code\": \"\",\n  \"type\": \"\",\n  \"message\": \"\"\n}"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "type": "api-oas-v2",
  "children": [
    {
      "text": ""
    }
  ]
}