> ## Documentation Index
> Fetch the complete documentation index at: https://docs.powerdrill.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> Uploads a file. 

# Upload local file

### Introduction

You can use this endpoint to upload your local file and then use the `file_key` you obtained to create a data source through the [Create data source](/api-reference/v2/create-data-source) endpoint.

Only files with the following extensions are supported: **.csv**, **.tsv**, **.md**, **.mdx**, **.json**, **.txt**, **.pdf**, **.pptx**, **.ppt**, **.doc**, **.docx**, **.xls**, or **.xlsx**.

<Warning>
  For optimal upload efficiency, we recommend using this endpoint for files **smaller than 1 MB**. For files larger than 1 MB, please initiate a [multipart upload](/api-reference/v2/initiate-multipart-upload) task.
</Warning>

**Example request:**

<CodeGroup>
  ```curl cURL theme={null}
  curl --location 'http://ai.data.cloud/api/v2/team/file/upload-datasource' \
  --header 'x-pd-api-key: <api-key>' \
  --header 'x-pd-external-trace-id;' \
  --header 'Cookie: Cookie_1=value; metabase.DEVICE=f3cb3dbb-ef62-4026-845e-1480431c751d' \
  --form 'file=@"/Users/username/Downloads/c5168946-8f1a-4c92-a167-5e3be57745be.csv"' \
  --form 'user_id="tmm-cm5ao3yoe00zm01l1u1e7p3pj"'
  ```

  ```python Python theme={null}
  import requests

  url = "http://ai.data.cloud/api/v2/team/file/upload-datasource"

  payload = {'user_id': 'tmm-cm5ao3yoe00zm01l1u1e7p3pj'}
  files=[
    ('file',('c5168946-8f1a-4c92-a167-5e3be57745be.csv',open('/Users/jiaoqi/Downloads/c5168946-8f1a-4c92-a167-5e3be57745be.csv','rb'),'text/csv'))
  ]
  headers = {
    'x-pd-api-key': '<api-key>',
    'x-pd-external-trace-id': '',
    'Cookie': 'Cookie_1=value; metabase.DEVICE=f3cb3dbb-ef62-4026-845e-1480431c751d'
  }

  response = requests.request("POST", url, headers=headers, data=payload, files=files)

  print(response.text)
  ```
</CodeGroup>

**Example response:**

```json 200 theme={null}
{
  "code": 0,
  "data": {
    "file_object_key": "/tmp/sdgsagdsgsadgasdg.csv"
  }
}
```


## OpenAPI

````yaml post /v2/team/file/upload-datasource
openapi: 3.0.1
info:
  title: Team Open API Snake
  description: ''
  version: 1.0.0
servers:
  - url: https://ai.data.cloud/api
    description: 体验环境
security:
  - apikey-header-x-pd-api-key: []
tags:
  - name: Session
  - name: Dataset
  - name: Data source
  - name: File
  - name: Job
paths:
  /v2/team/file/upload-datasource:
    post:
      tags:
        - File
      summary: Upload local file
      description: >-
        Uploads a local file in one of the following formats:  **.csv**,
        **.tsv**, **.md**, **.mdx**, **.json**, **.txt**, **.pdf**, **.pptx**, 
        **.docx**, **.xls**, or **.xlsx**.


        You can use this endpoint to upload your local file and then use the
        `file_object_key` you obtained to create a data source. For a detailed
        guide, refer to [How to Upload Local
        Files](/developer-guides/upload-file).
      parameters:
        - name: x-pd-external-trace-id
          in: header
          description: >-
            The trace ID you set in your system to trace this request. It can be
            up to 128 characters in length. If the request fails, you can
            provide it to the Powerdrill team to help with troubleshooting.
          required: false
          example: ''
          schema:
            type: string
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  format: binary
                  type: string
                  description: >-
                    The file to be uploaded. This is a required field and should
                    contain the file data. For example, `--form
                    'file=@"/Users/jiaoqi/Downloads/0f9a7ebd-7a2a-454a-8cd9-96accffa3107.csv"'`.
                  example: ''
                user_id:
                  description: >-
                    Your user ID, which uniquely identifies you within your
                    team. To obtain your ID:


                    - If you're the team admin, refer to [Check user
                    information](/enterprise/users#check-user-information).

                    - If you're a system or virtual user, ask your team admin to
                    check your user ID by referring to [Check user
                    information](/enterprise/users#check-user-information).
                  example: ''
                  type: string
              required:
                - file
                - user_id
            examples: {}
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    description: >-
                      Status code. **0** indicates that the operation is
                      successful. Otherwise, the operation fails. For error
                      troubleshooting, refer to [Error
                      Codes](/api-reference/error-codes).
                  data:
                    type: object
                    properties:
                      file_object_key:
                        type: string
                        description: The object storage path to the file.
                    required:
                      - file_object_key
                    description: The returned data object.
                required:
                  - data
                  - code
              example:
                code: 0
                data:
                  file_object_key: /tmp/sdgsagdsgsadgasdg.csv
          headers:
            x-pd-trace-id:
              example: ''
              required: true
              description: >-
                The trace ID returned by Powerdrill. If a failure occurs, you
                can provide it to the Powerdrill team to assist with
                troubleshooting.
              schema:
                type: string
      deprecated: false
      security:
        - apikey-header-x-pd-api-key: []
components:
  securitySchemes:
    apikey-header-x-pd-api-key:
      type: apiKey
      in: header
      name: x-pd-api-key

````