addAttachment

suspend fun addAttachment(name: String, contentType: String, filePath: String): Result<FormAttachment>

Adds a new attachment to this AttachmentsFormElement from the specified file.

The attachment name is provided by the name parameter. When useOriginalFilename is true the provided value will be used, but when useOriginalFilename is false the name parameter is ignored and one is generated automatically instead.

FileNotFoundException will be set if the file does not exist.

MaxAttachmentCountConstraintException will be set if adding this attachment would exceed the maximum number of attachments allowed.

MaxAttachmentDurationConstraintException will be set if the attachment exceeds the maximum duration specified by AudioFormInput.maxDuration or VideoFormInput.maxDuration.

MaxAttachmentSizeConstraintException will be set if the attachment exceeds the maximum size specified by DocumentFormInput.maxFileSize.

IncorrectAttachmentTypeException will be set if the type of the FormAttachment does not match an allowed AttachmentsFormInputType.

Return

A Result containing the new FormAttachment.

Since

300.0.0

Parameters

name

The attachment name.

contentType

The type of content.

filePath

Path to a file that will be used for the attachment's content.


suspend fun addAttachment(contentType: String, data: ByteArray, name: String? = null): Result<FormAttachment>

Adds a new attachment to this AttachmentsFormElement.

The name parameter is optional. If omitted, an attachment name is generated automatically. If name is provided and useOriginalFilename is true, it is used as the attachment name. If useOriginalFilename is false, name is ignored and an attachment name is generated automatically.

If the attachment is an image and it exceeds the maximum size specified by ImageFormInput.maxImageSize, it will be resized to meet that requirement before being added.

MaxAttachmentCountConstraintException will be set if adding this attachment would exceed the maximum number of attachments allowed.

MaxAttachmentDurationConstraintException will be set if the attachment exceeds the maximum duration specified by AudioFormInput.maxDuration or VideoFormInput.maxDuration.

MaxAttachmentSizeConstraintException will be set if the attachment exceeds the maximum size specified by DocumentFormInput.maxFileSize.

IncorrectAttachmentTypeException will be set if the type of the FormAttachment does not match an allowed AttachmentsFormInputType.

IllegalStateException will be set if the provided data is empty.

Return

A Result containing the new FormAttachment.

Since

300.1.0

Parameters

contentType

The type of content.

data

The attachment data.

name

The attachment name.


suspend fun addAttachment(contentType: String, filePath: String): Result<FormAttachment>

Adds a new attachment to this AttachmentsFormElement from the specified file.

The attachment name is generated automatically. When you wish to provide a custom name and useOriginalFilename is true, use the overload of this method that takes a name parameter.

If the attachment is an image and it exceeds the maximum size specified by ImageFormInput.maxImageSize, it will be resized to meet that requirement before being added.

FileNotFoundException will be set if the file does not exist.

MaxAttachmentCountConstraintException will be set if adding this attachment would exceed the maximum number of attachments allowed.

MaxAttachmentDurationConstraintException will be set if the attachment exceeds the maximum duration specified by AudioFormInput.maxDuration or VideoFormInput.maxDuration.

MaxAttachmentSizeConstraintException will be set if the attachment exceeds the maximum size specified by DocumentFormInput.maxFileSize.

IncorrectAttachmentTypeException will be set if the type of the FormAttachment does not match an allowed AttachmentsFormInputType.

Return

A Result containing the new FormAttachment.

Since

300.1.0

Parameters

contentType

The type of content.

filePath

Path to a file that will be used for the attachment's content.


fun addAttachment(name: String, contentType: String, data: ByteArray): FormAttachment

Deprecated

Since 300.0.0. This method will not validate the duration of audio and video attachments. Use the suspend function addAttachment(contentType: String, data: ByteArray, name: String? = null) instead.

Replace with

addAttachment(contentType, data, name)

Adds a new attachment to this AttachmentsFormElement.

Return

The new FormAttachment.

Since

200.5.0

Parameters

name

the name of the attachment

contentType

the mime type of the attachment

data

the attachment data

Throws

if data is empty