---
title: "Attachments"
description: "Learn more about how Sentry can store additional files in the same request as event attachments."
url: https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments/
---

# Attachments | Sentry for java.util.logging

Sentry can enrich your events for further investigation by storing additional files, such as config or log files, as attachments.

## [Creating Attachments](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#creating-attachments)

The simplest way to create an attachment is to use a `path`. The SDK will read the contents of the file each time it prepares an event or transaction, then adds the attachment to the same [envelope](https://develop.sentry.dev/sdk/data-model/envelopes/). If the SDK can't read the file, the SDK logs an error message and drops the attachment.

```java
import io.sentry.Sentry;
import io.sentry.Attachment;

Attachment attachment = new Attachment("your/path/file.log");
```

Alternately, use `bytes` to initialize an attachment. When doing so, you also need to specify a filename.

```java
import io.sentry.Sentry;
import io.sentry.Attachment;

Attachment attachment = new Attachment(bytes, "file.log");
```

If your SDK supports offline caching, which is typical for mobile, each attachment is stored to disk for each event or transaction you capture when the device is offline. When using large attachments, this storage can consume the disk space if the device is offline for a longer time period. You can specify [maximum attachment size](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#maximum-attachment-size) to drop large attachments and avoid this issue.

In addition, you can set these parameters:

`filename`

The filename is the name of the file to display in Sentry. When using bytes you have to specify a filename, whereas with a path you don't as the SDK is going to use the last path component.

`contentType`

The type of content stored in this attachment. Any [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml) may be used; the default is `application/octet-stream`.

`mimetype`

The specific media content type that determines how the attachment is rendered in the Sentry UI. We currently support and can render the following MIME types:

* `text/plain`
* `text/css`
* `text/csv`
* `text/html`
* `text/javascript`
* `text/json` or `text/x-json` or `application/json` or `application/ld+json`
* `image/jpeg`
* `image/png`
* `image/gif`
* `image/webp`
* `image/avif`
* `video/webm`
* `video/mp4`

## [Uploading Attachments](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#uploading-attachments)

To add an attachment, you can either add it to the scope, pass it to any of the `capture` methods, or manipulate the list of attachments in an `EventProcessor` or `beforeSend`.

### [Passing Attachments to Capture](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#passing-attachments-to-capture)

You may pass attachments to any of the `capture` methods, for example, when capturing an exception:

```java
import io.sentry.Attachment;
import io.sentry.Hint;
import io.sentry.Sentry;

Attachment attachment = new Attachment("/path/to/file.txt");
Sentry.captureException(new IllegalStateException(), Hint.withAttachment(attachment));
```

### [Adding Attachments in `EventProcessor`](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#adding-attachments-in-eventprocessor)

You may also manipulate attachments in `EventProcessor`:

```java
import io.sentry.Attachment;
import io.sentry.EventProcessor;
import io.sentry.Hint;
import io.sentry.Sentry;
import io.sentry.SentryEvent;

class AttachmentManipulationEventProcessor implements EventProcessor {
  @Override
  public SentryEvent process(SentryEvent event, Hint hint) {
    hint.addAttachment(new Attachment("/path/to/file.txt"))
    return event;
  }
}

// Register the AttachmentManipulationEventProcessor using SentryOptions#addEventProcessor or Scope#addEventProcessor

// Send an event to Sentry. During construction of the event
// the attachment will be added by the event processor.
Sentry.captureMessage("Hello, world!");
```

Instead of adding attachments, you can also remove them, by setting a different (or empty) list of attachments using `Hint#setAttachments()`.

### [Adding Attachments in `beforeSend`](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#adding-attachments-in-beforesend)

Another way of adding attachments is using `beforeSend`:

```java
import io.sentry.Attachment;
import io.sentry.Hint;
import io.sentry.Sentry;

options.setBeforeSend((event, hint) -> {
  hint.addAttachment(new Attachment("/path/to/file.txt"))
  return event;
});
```

Instead of adding attachments, you can also remove them, by setting a different (or empty) list of attachments using `Hint#setAttachments()`.

### [Adding Attachments to the Scope](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#adding-attachments-to-the-scope)

Attachments live on the [Scope](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/scopes.md). You can either add an attachment on the global scope to be sent with every event or add it on the [local Scope](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/scopes.md#local-scopes) to just send the attachment with one specific event.

```java
import io.sentry.Sentry;
import io.sentry.Attachment;

Attachment fileAttachment = new Attachment("your/path/file.log");

// Global Scope
Sentry.configureScope(scope -> {
  scope.addAttachment(fileAttachment);
});

// Clear all attachments in the global Scope
Sentry.configureScope(scope -> {
  scope.clearAttachments();
});

// Local Scope
Sentry.withScope(scope -> {
  scope.addAttachment(fileAttachment);
  Sentry.captureMessage("my message");
});
```

Sentry allows at most 40MB for a compressed request, and at most 200MB of uncompressed attachments per event, including the crash report file (if applicable). Uploads exceeding this size are rejected with HTTP error `413 Payload Too Large` and the data is dropped immediately. To add larger or more files, consider secondary storage options.

Attachments persist for 30 days; if your total storage included in your quota is exceeded, attachments will not be stored. You can delete attachments or their containing events at any time. Deleting an attachment does not affect your quota - Sentry counts an attachment toward your quota as soon as it is stored.

Learn more about how attachments impact your [quota](https://docs.sentry.io/pricing/quotas.md).

### [Access to Attachments](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#access-to-attachments)

To limit access to attachments, navigate to your organization's **General Settings**, then select the *Attachments Access* dropdown to set appropriate access — any member of your organization, the organization billing owner, member, admin, manager, or owner.

By default, access is granted to all members when storage is enabled. If a member does not have access to the project, the ability to download an attachment is not available; the button will be greyed out in Sentry. The member may only view that an attachment is stored.

## [Viewing Attachments](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#viewing-attachments)

Attachments display on the bottom of the **Issue Details** page for the event that is shown.

Alternately, attachments also appear in the *Attachments* tab on the **Issue Details** page, where you can view the *Type* of attachment, as well as associated events. Click the Event ID to open the **Issue Details** of that specific event.

## [Maximum Attachment Size](https://docs.sentry.io/platforms/java/guides/jul/enriching-events/attachments.md#maximum-attachment-size)

The maximum size for each attachment is set on `SentryOptions.maxAttachmentSize`.

The scale is bytes and the default is `20 MiB`. Please also check the [maximum attachment size of Relay](https://docs.sentry.io/product/relay/options.md) to make sure your attachments don't get discarded there.

```java
import io.sentry.Sentry;

Sentry.init(options -> {
  options.setMaxAttachmentSize(5 * 1024 * 1024); // 5 MiB
});
```
