---
title: Upload a file
slug: feature-experimentation/api/upload-a-file
docTags: 
createdAt: 2026-10-13T18:16:15.508Z
---

{
  "id": "WM1m029APBcHZhVBR8UAj",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/files",
    "servers": [
      {
        "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/files"
      }
    ],
    "name": "Upload a file",
    "description": "<p>Upload a file to be used by any feature that needs file attachments\n(e.g., test plans on rules). Returns a file_id and file_url\n(backend proxy path) for referencing the file.</p>\n<p>Requires FLAGS_MODIFY permission on the project.</p>",
    "contentType": "multipart/form-data",
    "request": {
      "pathParameters": [
        {
          "kind": "required",
          "name": "project_id",
          "type": "integer",
          "example": 12345,
          "description": "The project identifier"
        }
      ],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        }
      ],
      "queryParameters": [
        {
          "kind": "optional",
          "name": "file_type",
          "type": "string",
          "description": "<p>Restricts which file formats are accepted. When <code>test_plan</code>, only document formats (pdf, doc, docx, md) are allowed. When <code>variation_image</code>, only image formats (png, jpg, jpeg, gif, svg) are allowed. Omitting this parameter accepts all supported types.</p>",
          "enum": [
            "test_plan",
            "variation_image"
          ]
        }
      ],
      "bodyDataParameters": [],
      "formDataParameters": [
        {
          "name": "file",
          "kind": "required",
          "type": "string<binary>",
          "description": "<p>The file to upload. Allowed types depend on <code>file_type</code>: documents (pdf, doc, docx, md, max 10 MB) or images (png, jpg, jpeg, gif, svg, max 5 MB).</p>",
          "format": "binary"
        }
      ],
      "oAuthParameters": [
        {
          "id": "apiKey",
          "name": "apiKey",
          "kind": "optional",
          "type": "http",
          "scheme": "bearer"
        },
        {
          "id": "OAuth2",
          "name": "OAuth2",
          "kind": "optional",
          "type": "oauth2",
          "description": "Write applications that authenticate with the REST API via OAuth 2.0.",
          "oauth2Flows": {
            "authorizationCode": {
              "authorizationUrl": "https://app.optimizely.com/oauth2/authorize",
              "tokenUrl": "https://app.optimizely.com/oauth2/token",
              "scopes": {
                "all": "Grants all access"
              }
            }
          },
          "requiredScopes": [
            "read",
            "write"
          ]
        }
      ],
      "cookieParameters": []
    },
    "responses": [
      {
        "statusCode": "201",
        "description": "File uploaded successfully",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "FileUploadResponse",
            "schema": [
              {
                "name": "content_type",
                "kind": "required",
                "type": "string",
                "description": "MIME type of the uploaded file"
              },
              {
                "name": "file_id",
                "kind": "required",
                "type": "string",
                "description": "<p>Unique file identifier (UUID)</p>"
              },
              {
                "name": "file_name",
                "kind": "required",
                "type": "string",
                "description": "Original filename"
              },
              {
                "name": "file_size",
                "kind": "required",
                "type": "integer",
                "description": "File size in bytes"
              },
              {
                "name": "file_url",
                "kind": "required",
                "type": "string",
                "description": "Backend proxy path for downloading the file"
              }
            ],
            "modelRef": "#/components/schemas/FileUploadResponse",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "400",
        "description": "Malformed requests and invalid parameter names and types",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "401",
        "description": "Invalid credentials",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "403",
        "description": "Do not have permission to perform the operation",
        "jsonExample": "",
        "isExpanded": true
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "PERErExjmgpBEHhCgdg48",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://api.optimizely.com/flags/v1//projects/{project_id}/files \\\n     --header 'accept: application/json' \\\n     --header 'content-type: multipart/form-data' \\\n     --form 'file=@\"/path/to/file\"'"
        },
        {
          "id": "s49GA5RS2XPEsESvYClu0",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"multipart/form-data\");\n\nvar formdata = new FormData();\nformdata.append(\"file\", fileInput.files[0], \"file\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: formdata,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.optimizely.com/flags/v1//projects/{project_id}/files\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "t8vfGhz2Ti9CQWUPJ9cNa",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"net/http\"\n\nurl = URI(\"https://api.optimizely.com/flags/v1//projects/{project_id}/files\")\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\"\nform_data = [['file', File.open('/path/to/file')]]\nrequest.set_form form_data, 'multipart/form-data'\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "DPjmBw9TgiQJeDu-2UPIy",
          "language": "python",
          "label": "Python",
          "code": "import requests\n\nurl = \"https://api.optimizely.com/flags/v1//projects/{project_id}/files\"\n\npayload = {}\nfiles=[\n   ('file',('file',open('/path/to/file','rb'),'application/octet-stream'))\n]\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'multipart/form-data'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload, files=files)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "PERErExjmgpBEHhCgdg48"
    },
    "results": {
      "languages": [
        {
          "id": "69mIHLR7I-sho53vlejYy",
          "language": "201",
          "code": "// File uploaded successfully\n{\n  \"content_type\": \"\",\n  \"file_id\": \"\",\n  \"file_name\": \"\",\n  \"file_size\": 0,\n  \"file_url\": \"\"\n}"
        },
        {
          "id": "dBRnDPGSeni0s8O14YLB-",
          "language": "400",
          "code": "// Malformed requests and invalid parameter names and types\n"
        },
        {
          "id": "I7X-OHPYskYlsw5PX-0ZP",
          "language": "401",
          "code": "// Invalid credentials\n"
        },
        {
          "id": "7V4L8UbustZ5RfPjLjBtS",
          "language": "403",
          "code": "// Do not have permission to perform the operation\n"
        }
      ],
      "selectedLanguageId": "69mIHLR7I-sho53vlejYy"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}