> ## 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.

# How to Upload Local Files

> How to quickly upload local files to create data sources

The [`POST api/v1/datasets/{datasetId}/datasources`](https://docs.powerdrill.ai/api-reference/create-data-source) and [`POST /v1/datasources`](https://docs.powerdrill.ai/api-reference/create-data-source-without-dataset) endpoints allow you to upload your data in two methods:

* From a public URL: Use the `url` parameter.

* From your local storage: Use the `fileKey` parameter.

This guide focuses on the latter—uploading a local file to create a data source.

***

## Authentication

All requests to Powerdrill must include an `x-pd-api-key` header with your API key.

To get your API key, see [Quick Start](https://docs.powerdrill.ai/developer-guides/quick-start.md#step-1-get-your-api-key).

***

## Step 1. Upload your local file and obtain the `fileKey`

Use the [POST /v1/file/upload\_datasource](https://docs.powerdrill.ai/api-reference/upload-file.md) endpoint to upload your local file. After the upload, the response will include a `fileKey`. Save this `fileKey` to create a data source using the [Create data source](https://docs.powerdrill.ai/api-reference/create-data-source.md) endpoint.

Supported file formats include: **.csv**, **.tsv**, **.md**, **.mdx**, **.json**, **.txt**, **.pdf**, **.pptx**, **.ppt**, **.doc**, **.docx**, **.xls**, and **.xlsx**.

Here's an example in cURL:

```curl Example request: theme={null}
curl --location 'http://ai.data.cloud/api/v1/file/upload_datasource' \
--header 'Content-Type: multipart/form-data' \
--header 'x-pd-api-key: <api-key>' \
--header 'x-pd-api-agent-id: GENERAL' \
--form 'file=@"<file_path>"'
```

> [!TIP]
>
> When making a request:
>
> * Replace `<api-key>` with your actual API key.
>
> * Replace `<file_path>` with the actual full path to your file, for example, `/Users/test/workspace/sales_2024.csv`.

Here's an example response:

```json Example response: theme={null}
{
  "code": 0,
  "data": {
    "fileKey": "/tmp/sdgsagdsgsadgasdg"
  }
}
```

Extract the `fileKey` value from the response for later use. In this example, it is `/tmp/sdgsagdsgsadgasdg`.

***

## Step 2. Create a data source

Now, create a data source to embed and synchronize it with your AI Workspace.

You can do this by sending a request to either the [`POST api/v1/datasets/{datasetId}/datasources`](https://docs.powerdrill.ai/api-reference/create-data-source) endpoint or the [`POST /v1/datasources`](https://docs.powerdrill.ai/api-reference/create-data-source-without-dataset) endpoint.

The example below demonstrates the use of the [`POST /v1/datasources`](https://docs.powerdrill.ai/api-reference/create-data-source-without-dataset) endpoint.

```curl Example request: theme={null}
curl --location 'https://ai.data.cloud/api/v1/datasets/cm3my37en3q36017q7x3hyyf4/datasources' \
  --header 'x-pd-api-key: $PD_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "test.csv",
  "fileName": "test.csv",
  "type": "FILE",
  "fileKey": "/tmp/sdgsagdsgsadgasdg"
}'
```

> [!TIP]
>
> When making a request:
>
> * Replace `<api-key>` with your actual API key.
> * Set `fileKey` to your actual one.

```json Example response: theme={null}
{
  "code": 0,
  "data": {
    "id": "datasource-cadsgfsdagasgadsg",
    "datasetId": "dataset-dagasdgasgasg",
    "name": "test.csv",
    "fileName": "test.csv",
    "type": "FILE",
    "status": "pending"
  }
}
```

Obtain the `id` (data source ID) and `datasetId` (dataset ID) for later use. In this example, the data source ID is `datasource-cadsgfsdagasgadsg` and the dataset ID is `dataset-dagasdgasgasg`.

***

## Step 3. Check data source status

The data source must be in the **synched** state to be ready for use. To check its status, use the [`GET v1/datasets/{datasetId}/datasources/{datasourceId}`](https://docs.powerdrill.ai/api-reference/get-data-source) endpoint.

Here's an example:

```curl Example request theme={null}
curl --request GET \
  --url https://ai.data.cloud/api/v1/datasets/dataset-dagasdgasgasg/datasources/datasource-cadsgfsdagasgadsg \
  --header 'x-pd-api-key: <api-key>'
```

Check the status in the response:

```json Example response: theme={null}
{
  "code": 0,
  "data": {
    "id": "datasource-cadsgfsdagasgadsg",
    "datasetId": "dataset-dagasdgasgasg",
    "name": "test.csv",
    "fileName": "test.csv",
    "type": "FILE",
    "status": "synched"
  }
}
```

In this example, the data source is in the `synched` state and is ready for use in [data analysis jobs](https://docs.powerdrill.ai/api-reference/create-job.md).

Other possible statuses include:

* **`pending`**: Waiting to be processed.
* **`running`**: Currently being processed.
* **`error`**: Processing failed.

> [!TIP]
>
> If the status is `pending` or `running`, wait for some time and check again until it changes to `synched`.
>
> If the status is `error`, you'll need to re-upload the file by starting from [Step 1](#step-1-upload-your-local-file-and-obtain-fileKey).

***

## Need more help?

> [card] [Post to our help community](https://discord.com/invite/ZsyyD5ysRC)
>
> Get answers from our  members

> [card] [Contact us](mailto:service@powerdrill.ai)
>
> Tell us more and we'll help you out


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.