# Upload a paper (/docs/sdks/papers/upload)



Uploading a document creates a [paper](/docs/core-concepts/papers). By default, the SDK waits until processing finishes and returns the ready paper.

All examples assume you've [created a client](/docs/sdks/javascript#create-a-client). See [Limits](/docs/platform/limits) for supported file types and sizes.

## Upload a file [#upload-a-file]

<Tabs groupId="language" items="[&#x22;JavaScript&#x22;]">
  <Tab value="JavaScript">
    ```ts
    import { readFile } from "node:fs/promises";

    const file = await readFile("./report.pdf");

    const paper = await paperful.papers.upload({
      file,
      fileName: "report.pdf",
    });

    console.log(paper.id, paper.status);
    ```
  </Tab>
</Tabs>

`fileName` is required when it can't be inferred from the file. `File` objects carry their own name, while buffers don't.

## Track progress [#track-progress]

Pass `onEvent` to follow processing as it happens.

<Tabs groupId="language" items="[&#x22;JavaScript&#x22;]">
  <Tab value="JavaScript">
    ```ts
    const paper = await paperful.papers.upload({
      file,
      fileName: "report.pdf",
      /* [!code ++:5] */
      onEvent: ({ event, data }) => {
        if (event === "progress") {
          console.log(`${data.processed}/${data.total}`);
        }
      },
    });
    ```
  </Tab>
</Tabs>

| Event       | Description                                            |
| ----------- | ------------------------------------------------------ |
| `started`   | Processing has started.                                |
| `progress`  | Processing advanced. Includes `processed` and `total`. |
| `completed` | Processing finished. Includes the paper.               |

## Attach metadata [#attach-metadata]

Pass `metadata` to tag the paper with your own [metadata](/docs/core-concepts/papers#metadata). You can then use it to [filter lists](/docs/sdks/papers/list#filter-by-metadata) and [searches](/docs/sdks/search/query#filter-by-metadata).

<Tabs groupId="language" items="[&#x22;JavaScript&#x22;]">
  <Tab value="JavaScript">
    ```ts
    const paper = await paperful.papers.upload({
      file,
      fileName: "invoice.pdf",
      /* [!code ++:4] */
      metadata: {
        category: "invoice",
        amount: 150,
      },
    });
    ```
  </Tab>
</Tabs>

## Don't wait for processing [#dont-wait-for-processing]

Set `waitForProcessing` to `false` to return as soon as the upload is accepted. Processing continues in the background, and you can [check on the paper later](/docs/sdks/papers/retrieve).

<Tabs groupId="language" items="[&#x22;JavaScript&#x22;]">
  <Tab value="JavaScript">
    ```ts
    const paper = await paperful.papers.upload({
      file,
      fileName: "report.pdf",
      /* [!code ++] */
      waitForProcessing: false,
    });
    ```
  </Tab>
</Tabs>

## Options [#options]

<TypeTable
  type="{
  file: {
    description: 'The document to upload.',
    type: 'File | Buffer',
    default: undefined,
  },
  fileName: {
    description: 'The name of the file, including its extension.',
    type: 'string',
    default: 'Inferred from the file if possible',
  },
  metadata: {
    description: 'Metadata to attach to the paper.',
    type: 'Record<string, unknown>',
    default: undefined,
  },
  waitForProcessing: {
    description: 'Whether to wait for processing to finish before returning.',
    type: 'boolean',
    default: true,
  },
  onEvent: {
    description: 'Called with each processing event.',
    type: '(event: { event: string; data: any }) => void',
    default: undefined,
  },
}"
/>
