Package io.sentry

Class Attachment

java.lang.Object
io.sentry.Attachment

public final class Attachment extends Object
You can use an attachment to store additional files alongside an event or transaction.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Attachment(@org.jetbrains.annotations.NotNull byte[] bytes, @NotNull String filename)
    Initializes an Attachment with bytes and a filename.
    Attachment(@org.jetbrains.annotations.NotNull byte[] bytes, @NotNull String filename, @Nullable String contentType)
    Initializes an Attachment with bytes, a filename, and a content type.
    Attachment(@org.jetbrains.annotations.NotNull byte[] bytes, @NotNull String filename, @Nullable String contentType, boolean addToTransactions)
    Initializes an Attachment with bytes, a filename, a content type, and addToTransactions.
    Attachment(@org.jetbrains.annotations.NotNull byte[] bytes, @NotNull String filename, @Nullable String contentType, @Nullable String attachmentType, boolean addToTransactions)
    Initializes an Attachment with bytes, a filename, a content type, and addToTransactions.
    Attachment(@NotNull JsonSerializable serializable, @NotNull String filename, @Nullable String contentType, @Nullable String attachmentType, boolean addToTransactions)
    Initializes an Attachment with bytes factory, a filename, a content type, and addToTransactions.
    Attachment(@NotNull String pathname)
    Initializes an Attachment with a path.
    Attachment(@NotNull String pathname, @NotNull String filename)
    Initializes an Attachment with a path and a filename.
    Attachment(@NotNull String pathname, @NotNull String filename, @Nullable String contentType)
    Initializes an Attachment with a path, a filename, and a content type.
    Attachment(@NotNull String pathname, @NotNull String filename, @Nullable String contentType, boolean addToTransactions)
    Initializes an Attachment with a path, a filename, a content type, and addToTransactions.
    Attachment(@NotNull String pathname, @NotNull String filename, @Nullable String contentType, boolean addToTransactions, @Nullable String attachmentType)
    Initializes an Attachment with a path, a filename, a content type, addToTransactions, and attachmentType.
    Attachment(@NotNull String pathname, @NotNull String filename, @Nullable String contentType, @Nullable String attachmentType, boolean addToTransactions)
    Initializes an Attachment with a path, a filename, a content type, and addToTransactions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull Attachment
    fromScreenshot(byte[] screenshotBytes)
    Creates a new Screenshot Attachment
    static @NotNull Attachment
    fromThreadDump(byte[] bytes)
    Creates a new Thread Dump Attachment
    static @NotNull Attachment
    Creates a new View Hierarchy Attachment
    @Nullable String
    Returns the attachmentType type
    @org.jetbrains.annotations.Nullable byte[]
    Gets the bytes of the attachment.
    @Nullable String
    Gets the content type of the attachment.
    @NotNull String
    Gets the name of the attachment to display in Sentry.
    @Nullable String
    Gets the pathname string of the attachment.
    Provides the bytes of the attachment.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Attachment

      public Attachment(@NotNull @org.jetbrains.annotations.NotNull byte[] bytes, @NotNull @NotNull String filename)
      Initializes an Attachment with bytes and a filename. Sets addToTransaction to false .
      Parameters:
      bytes - The bytes of file.
      filename - The name of the attachment to display in Sentry.
    • Attachment

      public Attachment(@NotNull @org.jetbrains.annotations.NotNull byte[] bytes, @NotNull @NotNull String filename, @Nullable @Nullable String contentType)
      Initializes an Attachment with bytes, a filename, and a content type. Sets addToTransaction to false.
      Parameters:
      bytes - The bytes of file.
      filename - The name of the attachment to display in Sentry.
      contentType - The content type of the attachment.
    • Attachment

      public Attachment(@NotNull @org.jetbrains.annotations.NotNull byte[] bytes, @NotNull @NotNull String filename, @Nullable @Nullable String contentType, boolean addToTransactions)
      Initializes an Attachment with bytes, a filename, a content type, and addToTransactions.
      Parameters:
      bytes - The bytes of file.
      filename - The name of the attachment to display in Sentry.
      contentType - The content type of the attachment.
      addToTransactions - true if the SDK should add this attachment to every ITransaction or set to false if it shouldn't.
    • Attachment

      public Attachment(@NotNull @org.jetbrains.annotations.NotNull byte[] bytes, @NotNull @NotNull String filename, @Nullable @Nullable String contentType, @Nullable @Nullable String attachmentType, boolean addToTransactions)
      Initializes an Attachment with bytes, a filename, a content type, and addToTransactions.
      Parameters:
      bytes - The bytes of file.
      filename - The name of the attachment to display in Sentry.
      contentType - The content type of the attachment.
      attachmentType - the attachment type.
      addToTransactions - true if the SDK should add this attachment to every ITransaction or set to false if it shouldn't.
    • Attachment

      public Attachment(@NotNull @NotNull JsonSerializable serializable, @NotNull @NotNull String filename, @Nullable @Nullable String contentType, @Nullable @Nullable String attachmentType, boolean addToTransactions)
      Initializes an Attachment with bytes factory, a filename, a content type, and addToTransactions.
      Parameters:
      serializable - A json serializable holding the attachment payload
      filename - The name of the attachment to display in Sentry.
      contentType - The content type of the attachment.
      attachmentType - the attachment type.
      addToTransactions - true if the SDK should add this attachment to every ITransaction or set to false if it shouldn't.
    • Attachment

      public Attachment(@NotNull @NotNull String pathname)
      Initializes an Attachment with a path. The filename of the file located at the path is used. Sets addToTransaction to false.

      The file located at the pathname is read lazily when the SDK captures an event or transaction not when the attachment is initialized. The pathname string is converted into an abstract pathname before reading the file.

      Parameters:
      pathname - The pathname string of the file to upload as an attachment.
    • Attachment

      public Attachment(@NotNull @NotNull String pathname, @NotNull @NotNull String filename)
      Initializes an Attachment with a path and a filename. Sets addToTransaction to false .

      The file located at the pathname is read lazily when the SDK captures an event or transaction not when the attachment is initialized. The pathname string is converted into an abstract pathname before reading the file.

      Parameters:
      pathname - The pathname string of the file to upload as an attachment.
      filename - The name of the attachment to display in Sentry.
    • Attachment

      public Attachment(@NotNull @NotNull String pathname, @NotNull @NotNull String filename, @Nullable @Nullable String contentType)
      Initializes an Attachment with a path, a filename, and a content type. Sets addToTransaction to false.

      The file located at the pathname is read lazily when the SDK captures an event or transaction not when the attachment is initialized. The pathname string is converted into an abstract pathname before reading the file.

      Parameters:
      pathname - The pathname string of the file to upload as an attachment.
      filename - The name of the attachment to display in Sentry.
      contentType - The content type of the attachment.
    • Attachment

      public Attachment(@NotNull @NotNull String pathname, @NotNull @NotNull String filename, @Nullable @Nullable String contentType, @Nullable @Nullable String attachmentType, boolean addToTransactions)
      Initializes an Attachment with a path, a filename, a content type, and addToTransactions.

      The file located at the pathname is read lazily when the SDK captures an event or transaction not when the attachment is initialized. The pathname string is converted into an abstract pathname before reading the file.

      Parameters:
      pathname - The pathname string of the file to upload as an attachment.
      filename - The name of the attachment to display in Sentry.
      contentType - The content type of the attachment.
      attachmentType - The attachment type.
      addToTransactions - true if the SDK should add this attachment to every ITransaction or set to false if it shouldn't.
    • Attachment

      public Attachment(@NotNull @NotNull String pathname, @NotNull @NotNull String filename, @Nullable @Nullable String contentType, boolean addToTransactions)
      Initializes an Attachment with a path, a filename, a content type, and addToTransactions.

      The file located at the pathname is read lazily when the SDK captures an event or transaction not when the attachment is initialized. The pathname string is converted into an abstract pathname before reading the file.

      Parameters:
      pathname - The pathname string of the file to upload as an attachment.
      filename - The name of the attachment to display in Sentry.
      contentType - The content type of the attachment.
      addToTransactions - true if the SDK should add this attachment to every ITransaction or set to false if it shouldn't.
    • Attachment

      public Attachment(@NotNull @NotNull String pathname, @NotNull @NotNull String filename, @Nullable @Nullable String contentType, boolean addToTransactions, @Nullable @Nullable String attachmentType)
      Initializes an Attachment with a path, a filename, a content type, addToTransactions, and attachmentType.

      The file located at the pathname is read lazily when the SDK captures an event or transaction not when the attachment is initialized. The pathname string is converted into an abstract pathname before reading the file.

      Parameters:
      pathname - The pathname string of the file to upload as an attachment.
      filename - The name of the attachment to display in Sentry.
      contentType - The content type of the attachment.
      addToTransactions - true if the SDK should add this attachment to every ITransaction or set to false if it shouldn't.
      attachmentType - The content type of the attachment.
  • Method Details

    • getBytes

      @Nullable public @org.jetbrains.annotations.Nullable byte[] getBytes()
      Gets the bytes of the attachment.
      Returns:
      the bytes.
    • getSerializable

      @Nullable public @Nullable JsonSerializable getSerializable()
      Provides the bytes of the attachment.
      Returns:
      the bytes factory responsible for providing the bytes.
    • getPathname

      @Nullable public @Nullable String getPathname()
      Gets the pathname string of the attachment.
      Returns:
      the pathname string.
    • getFilename

      @NotNull public @NotNull String getFilename()
      Gets the name of the attachment to display in Sentry.
      Returns:
      the filename.
    • getContentType

      @Nullable public @Nullable String getContentType()
      Gets the content type of the attachment. The server infers "application/octet-stream" if not set.
      Returns:
      the content type or null if not set.
    • getAttachmentType

      @Nullable public @Nullable String getAttachmentType()
      Returns the attachmentType type
      Returns:
      the attachmentType
    • fromScreenshot

      @NotNull public static @NotNull Attachment fromScreenshot(byte[] screenshotBytes)
      Creates a new Screenshot Attachment
      Parameters:
      screenshotBytes - the array bytes
      Returns:
      the Attachment
    • fromViewHierarchy

      @NotNull public static @NotNull Attachment fromViewHierarchy(ViewHierarchy viewHierarchy)
      Creates a new View Hierarchy Attachment
      Parameters:
      viewHierarchy - the View Hierarchy
      Returns:
      the Attachment
    • fromThreadDump

      @NotNull public static @NotNull Attachment fromThreadDump(byte[] bytes)
      Creates a new Thread Dump Attachment
      Parameters:
      bytes - the array bytes
      Returns:
      the Attachment