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

# Confirm Attachment Upload

> Confirm that an attachment has been uploaded

Confirm that a file has been successfully uploaded to the presigned URL. This step is required before the attachment can be used in emails.

## Path Parameters

<ParamField path="id" type="string" required>
  The attachment ID received from the `createUpload` endpoint (e.g., `att_abc123`).
</ParamField>

## Examples

<CodeGroup>
  ```typescript JavaScript theme={null}
  import { MailBreeze } from "mailbreeze";

  const mailbreeze = new MailBreeze({ apiKey: "sk_live_xxx" });

  // After uploading the file to the presigned URL...
  const attachment = await mailbreeze.attachments.confirm({
    uploadToken: "token_xyz789",
  });

  console.log(attachment.id);       // "att_abc123"
  console.log(attachment.fileName); // "report.pdf"
  console.log(attachment.status);   // "uploaded"
  console.log(attachment.fileSize); // 1024000

  // Now use it in an email
  await mailbreeze.emails.send({
    from: "hello@yourdomain.com",
    to: "user@example.com",
    subject: "Your report",
    html: "<p>Report attached.</p>",
    attachmentIds: [attachment.id],
  });
  ```

  ```python Python theme={null}
  from mailbreeze import MailBreeze

  client = MailBreeze(api_key="sk_live_xxx")

  # After uploading the file to the presigned URL...
  attachment = await client.attachments.confirm(
      upload_token="token_xyz789",
  )

  print(attachment.id)        # "att_abc123"
  print(attachment.file_name) # "report.pdf"
  print(attachment.status)    # "uploaded"
  print(attachment.file_size) # 1024000

  # Now use it in an email
  await client.emails.send(
      from_="hello@yourdomain.com",
      to="user@example.com",
      subject="Your report",
      html="<p>Report attached.</p>",
      attachment_ids=[attachment.id],
  )
  ```

  ```go Go theme={null}
  client := mailbreeze.NewClient("sk_live_xxx")

  // After uploading the file to the presigned URL...
  attachment, err := client.Attachments.Confirm(ctx, &mailbreeze.ConfirmAttachmentParams{
      UploadToken: "token_xyz789",
  })
  if err != nil {
      log.Fatal(err)
  }

  fmt.Println(attachment.ID)       // "att_abc123"
  fmt.Println(attachment.FileName) // "report.pdf"
  fmt.Println(attachment.Status)   // "uploaded"
  fmt.Println(attachment.FileSize) // 1024000

  // Now use it in an email
  client.Emails.Send(ctx, &mailbreeze.SendEmailParams{
      From:          "hello@yourdomain.com",
      To:            []string{"user@example.com"},
      Subject:       "Your report",
      HTML:          "<p>Report attached.</p>",
      AttachmentIds: []string{attachment.ID},
  })
  ```

  ```php PHP theme={null}
  $mailbreeze = new MailBreeze('sk_live_xxx');

  // After uploading the file to the presigned URL...
  $result = $mailbreeze->attachments->confirm('att_abc123');

  echo $result['success'] ? 'Confirmed!' : 'Failed';

  // Now use it in an email
  $mailbreeze->emails->send([
      'from' => 'hello@yourdomain.com',
      'to' => 'user@example.com',
      'subject' => 'Your report',
      'html' => '<p>Report attached.</p>',
      'attachmentIds' => ['att_abc123'],
  ]);
  ```

  ```rust Rust theme={null}
  let client = Client::new("sk_live_xxx");

  // After uploading the file to the presigned URL...
  let attachment = client.attachments().confirm(ConfirmAttachmentParams {
      upload_token: "token_xyz789".to_string(),
  }).await?;

  println!("{}", attachment.id);        // "att_abc123"
  println!("{}", attachment.file_name); // "report.pdf"
  println!("{}", attachment.status);    // "uploaded"
  println!("{}", attachment.file_size); // 1024000

  // Now use it in an email
  client.emails().send(SendEmailParams {
      from: "hello@yourdomain.com".to_string(),
      to: vec!["user@example.com".to_string()],
      subject: Some("Your report".to_string()),
      html: Some("<p>Report attached.</p>".to_string()),
      attachment_ids: Some(vec![attachment.id]),
      ..Default::default()
  }).await?;
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.mailbreeze.com/api/v1/attachments/att_abc123/confirm \
    -H "Authorization: Bearer sk_live_xxx"
  ```
</CodeGroup>

## Response

<ResponseField name="success" type="boolean">
  Indicates whether the confirmation was successful.
</ResponseField>

```json Example Response theme={null}
{
  "success": true,
  "data": null,
  "meta": {
    "timestamp": "2024-01-15T10:30:00.000Z",
    "requestId": "req_abc123",
    "path": "/api/v1/attachments/att_abc123/confirm"
  }
}
```

## Attachment Status

| Status     | Description                                  |
| ---------- | -------------------------------------------- |
| `pending`  | Upload URL created but file not yet uploaded |
| `uploaded` | File uploaded and confirmed, ready for use   |
| `expired`  | Upload URL or attachment has expired         |

## Errors

| Code                  | HTTP Status | Description                                    |
| --------------------- | ----------- | ---------------------------------------------- |
| `UPLOAD_NOT_FOUND`    | 404         | Invalid or expired upload token                |
| `UPLOAD_NOT_COMPLETE` | 400         | File not yet uploaded to presigned URL         |
| `UPLOAD_EXPIRED`      | 400         | Upload URL has expired                         |
| `FILE_SIZE_MISMATCH`  | 400         | Uploaded file size doesn't match declared size |

<Note>
  Attachments expire 7 days after confirmation. If you need to send the same file again after expiration, you'll need to create a new upload.
</Note>

## Reusing Attachments

Once confirmed, an attachment ID can be reused in multiple emails until it expires:

```typescript theme={null}
// Same attachment in multiple emails
const attachmentId = "att_abc123";

await mailbreeze.emails.send({
  to: "user1@example.com",
  attachmentIds: [attachmentId],
  // ...
});

await mailbreeze.emails.send({
  to: "user2@example.com",
  attachmentIds: [attachmentId],
  // ...
});
```
