# Get Attachment Content — Gmail

> Return a Gmail attachment's content as base64 so a client can use it directly, for example to show an image inline or read a small text file. Call Find Emails with fields: ["subject", "attachments"], or Get Thread, first to get the message…

- Key: `gmail-get-attachment-content`
- Type: Action (Read-only)
- Version: 0.0.1
- App: Gmail (`gmail`) — https://pipedream.com/apps/gmail.md
- This page (HTML): https://pipedream.com/apps/gmail/actions/get-attachment-content
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/gmail/actions/get-attachment-content/get-attachment-content.mjs

## Description

Return a Gmail attachment's content as base64 so a client can use it directly, for example to show an image inline or read a small text file. Call **Find Emails** with `fields: ["subject", "attachments"]`, or **Get Thread**, first to get the message `id` and the attachment's `partId`. Not for saving a file to disk (use **Download Attachment**) or for listing a message's attachments (use **Find Emails** or **Get Thread**). `data` is standard padded base64 (`+` and `/`, not base64url), so it can go straight into `data:<mimeType>;base64,<data>`. `size` is the decoded byte length. Attachments larger than `maxBytes` are not downloaded: the result has `tooLarge: true`, the real `size`, a `message`, and `data: null`; the default limit is 2000000 bytes and it can be raised to at most 5000000. Returns `filename`, `mimeType`, `size`, `encoding` (always `base64`) and `data`. Example: messageId="19a2b3c4d5e6f789", partId="1" → `{ filename: "chart.png", mimeType: "image/png", size: 1843, encoding: "base64", data: "iVBORw0KGgo..." }`. [See the documentation](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages.attachments/get).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `messageId` | `string` | Yes | The id of the message containing the attachment, e.g. 19a2b3c4d5e6f789. Obtain this from Find Emails or Get Thread. |
| `partId` | `string` | Yes | The attachment's partId from the message's attachments list, e.g. 1 or 0.2. Get it from Find Emails with fields: ["subject", "attachments"], or from Get Thread. |
| `maxBytes` | `integer` | No | Largest attachment to return, in bytes, e.g. 2000000. Larger attachments are rejected before download. Defaults to 2000000; the maximum allowed is 5000000. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "gmail",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "gmail-get-attachment-content",
  arguments: {
    messageId: "Message ID",
    partId: "Part ID",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "gmail-get-attachment-content",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    gmail: { authProvisionId: "apn_xxxxxxx" },
    messageId: "Message ID",
    partId: "Part ID",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "gmail-get-attachment-content",
    "configured_props": {
      "gmail": { "authProvisionId": "apn_xxxxxxx" },
      "messageId": "Message ID",
      "partId": "Part ID"
    }
  }'
```

---

- App: https://pipedream.com/apps/gmail.md · All apps: https://pipedream.com/apps
