net.corda.node.services.persistence

## Class NodeAttachmentService

- net.corda.node.services.persistence.NodeAttachmentService

- All Implemented Interfaces:
    AcceptsFileUpload, AttachmentStorage, FileUploader

      public class NodeAttachmentService
      implements AttachmentStorage, AcceptsFileUpload

  Stores attachments in the specified local directory, which must exist. Doesn't allow new attachments to be uploaded.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface net.corda.node.services.api.AcceptsFileUpload

      `AcceptsFileUpload.DefaultImpls`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NodeAttachmentService(java.nio.file.Path storePath, com.codahale.metrics.MetricRegistry metrics)` Stores attachments in the specified local directory, which must exist. Doesn't allow new attachments to be uploaded.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `accepts(java.lang.String prefix)` Check if this service accepts this type of upload. For example if you are uploading interest rates this could be "my-service-interest-rates". Type here does not refer to file extentions or MIME types.
    `java.util.List<java.lang.String>` | `getAcceptableFileExtensions()` What file extensions are acceptable for the file to be handed to upload()
    `boolean` | `getAutomaticallyExtractAttachments()` If true, newly inserted attachments will be unzipped to a subdirectory of the storePath. This is intended for human browsing convenience: the attachment itself will still be the file (that is, edits to the extracted directory will not have any effect).
    `boolean` | `getCheckAttachmentsOnLoad()`
    `java.lang.String` | `getDataTypePrefix()` A string that prefixes the URLs, e.g. "attachments" or "interest-rates". Should be OK for URLs.
    `java.nio.file.Path` | `getStorePath()`
    `SecureHash` | `importAttachment(java.io.InputStream jar)` Inserts the given attachment into the store, does not close the input stream. This can be an intensive operation due to the need to copy the bytes to disk and hash them along the way.
    `Attachment` | `openAttachment(SecureHash id)` Returns a handle to a locally stored attachment, or null if it's not known. The handle can be used to open a stream for the data, which will be a zip/jar file.
    `void` | `setAutomaticallyExtractAttachments(boolean p)` If true, newly inserted attachments will be unzipped to a subdirectory of the storePath. This is intended for human browsing convenience: the attachment itself will still be the file (that is, edits to the extracted directory will not have any effect).
    `void` | `setCheckAttachmentsOnLoad(boolean p)`
    `java.lang.String` | `upload(java.io.InputStream data)` Accepts the data in the given input stream, and returns some sort of useful return message that will be sent back to the user in the response.

    - ### Methods inherited from interface net.corda.core.node.services.AttachmentStorage

      `importAttachment, openAttachment`

    - ### Methods inherited from interface net.corda.node.services.api.AcceptsFileUpload

      `accepts, getAcceptableFileExtensions, getDataTypePrefix`

    - ### Methods inherited from interface net.corda.core.node.services.FileUploader

      `accepts, upload`

- - ### Constructor Detail

    - #### NodeAttachmentService

          public NodeAttachmentService(java.nio.file.Path storePath,
                                       com.codahale.metrics.MetricRegistry metrics)

      Stores attachments in the specified local directory, which must exist. Doesn't allow new attachments to be uploaded.

  - ### Method Detail

    - #### getCheckAttachmentsOnLoad

          public boolean getCheckAttachmentsOnLoad()

    - #### setCheckAttachmentsOnLoad

          public void setCheckAttachmentsOnLoad(boolean p)

    - #### getAutomaticallyExtractAttachments

          public boolean getAutomaticallyExtractAttachments()

      If true, newly inserted attachments will be unzipped to a subdirectory of the storePath. This is intended for human browsing convenience: the attachment itself will still be the file (that is, edits to the extracted directory will not have any effect).

    - #### setAutomaticallyExtractAttachments

          public void setAutomaticallyExtractAttachments(boolean p)

      If true, newly inserted attachments will be unzipped to a subdirectory of the storePath. This is intended for human browsing convenience: the attachment itself will still be the file (that is, edits to the extracted directory will not have any effect).

    - #### openAttachment

          public Attachment openAttachment(SecureHash id)

      Returns a handle to a locally stored attachment, or null if it's not known. The handle can be used to open a stream for the data, which will be a zip/jar file.

    - #### importAttachment

          public SecureHash importAttachment(java.io.InputStream jar)

      Inserts the given attachment into the store, does not close the input stream. This can be an intensive operation due to the need to copy the bytes to disk and hash them along the way.

      Note that you should not pass a JarInputStream into this method and it will throw if you do, because access to the raw byte stream is required.

      Throws:
        - if the given byte stream has already been inserted.
        - if the given byte stream is empty or a JarInputStream.
        - if something went wrong.
      See Also:
        JarInputStream

    - #### getDataTypePrefix

          public java.lang.String getDataTypePrefix()

      A string that prefixes the URLs, e.g. "attachments" or "interest-rates". Should be OK for URLs.

    - #### getAcceptableFileExtensions

          public java.util.List<java.lang.String> getAcceptableFileExtensions()

      What file extensions are acceptable for the file to be handed to upload()

    - #### upload

          public java.lang.String upload(java.io.InputStream data)

      Accepts the data in the given input stream, and returns some sort of useful return message that will be sent back to the user in the response.

    - #### getStorePath

          public java.nio.file.Path getStorePath()

    - #### accepts

          public boolean accepts(java.lang.String prefix)

      Check if this service accepts this type of upload. For example if you are uploading interest rates this could be "my-service-interest-rates". Type here does not refer to file extentions or MIME types.