1. Tasks
  2. Attach file

Tasks

Attach file

Attaches a file to the stub. The file has to be uploaded to Stubber using a file field or other means before it can be attached.

TIP

You can also upload a file from a custom URL to Stubber using the upload_file task.

Basic usage

loading...

Parameters

fileuuid
required
string

The uuid of the file to be attached to the stub. This parameter is not required if the files parameter is set.


filename
string

Sets the filename of the attached file.


contentType
string

Sets the mime type of the attached file.


files
required
string

The list of files to be attached to the stub. Each item in the list accepts a fileuuid, filename, and contentType parameter. This parameter is not required if the fileuuid parameter is set.


Result

loading...

Properties

fileuuid
string

The uuid of the attached file.


Examples

Attach pdf

Attaches a pdf to a stub.

loading...

Attach pdf using a file details object

Attaches a pdf to a stub using the file object that was return by a previous task.

The fileuuid, filename and contentType should either be removed of left as empty strings.

The files parameter is an array of objects, also allowing the attaching of multiple files.

In this example, the file object is (substituted)[https://docs.stubber.com/docs/concepts/substitution#value-replacement-substitution] from the payload of the provider_create_pdf_quote task that runs just before this attach_file task. The entire object is returned in the substitution process.

NOTE

Consider Stubpost tasks Data

loading...
loading...

Attach multiple files

The following example attaches a pdf and an image to a stub. The files parameter is an array of objects, allowing the attaching of multiple files. ~~stub.attachments could also be used as value replacement variable substitution to attach multiple files from the current stub to another stub.

loading...

Using value replacement variable substitution to attach multiple files from the current stub to another stub. ~~stub.attachments refers to an array of file objects that were attached to the current stub.

loading...
NOTE

Consider Stubpost tasks Data

editor
        {
  "stubpost": {
    "tasks": {
      "attach_file": {
        "success": true,
        "payload": {
          "file": {
            "filename": "Attached PDF.pdf",
            "originalname": "Attached PDF.pdf",
            "fileuuid": "AaAaAaAa-BbBb-cCcC-DdDd-123456789012",
            "contentType": "application/pdf"
          },
          {
            "filename": "Attached Image.png",
            "originalname": "Attached Image.png",
            "fileuuid": "AaAaAaAa-BbBb-cCcC-DdDd-123456789014",
            "contentType": "image/png"
          }
        }
      }
    }
  }
}