attach file
Name | Description | Type | Modifier |
---|---|---|---|
path | Path to the location of the attached file. | String | None |
control name | Value of the name attribute in the HTML input tag. (see ) | String | None |
file name | (Optional) Attach the given file with a new name. | String | None |
mime type | (Optional) MIME type of the attached file. | String | None |
charset | (Optional) The character set (character encoding) to use. Standard charset values:
| Value Set | US-ASCII, ISO646-US, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16 |
Uploading Files With Real World Examples
- Imgur
- API-under-test: Image Upload
- control name argument:
- Required
- Input value: image
- Action lines:
path control name file name mime type charset attach file #cf local folder image file.png image/png UTF-8
- Imagify
- API-under-test: Image Upload
- control name argument:
- Required
- Input value: image
- file name argument: Required
- Action lines:
path control name file name mime type charset attach file #cf local folder image file.png image/png UTF-8
- Google Drive
- API-under-test: Multipart Upload
- mime type argument: When this argument is empty, the default value, applied by Google Drive, is application/x-zip.
- Action lines:
key value add http header Content-Type multipart/related; boundary=foo_bar_baz   path control name file name mime type charset attach file #cf local folder json file.png application/json UTF-8
- Facebook
- API-under-test: Video Upload
- file name argument: Required
- Action lines:
path control name file name mime type charset attach file #cf local folder source foo_bar.mp4 video/avi UTF-8
Example
Suppose that you'd like to attach a file with the following information:
- Path to the location of the attached file: /Users/test/Desktop/TestData/Web Services/testfile.png
- Value of the name attribute in the HTML input tag: file
- Attach the given file with a new name: file.png
- MIME type of the attached file: image/png
- The character set (character encoding) to use: UTF-8
Verify the if the HTTP status of the response is 201, which means the request has been fulfilled and resulted in a new resource being created.
create http request
 
key value
add http parameter path \\192.168.167.41\Log\data
 
path control name file name mime type charset
attach file /Users/test/Desktop/TestData/Web Services/testfile.png file file.png image/png UTF-8
 
uri method variable expected code
send http request http://192.168.167.41:8080/righteye.api/assessments/attachments/single POST >>tm result 201
- It is required that this built-in action must be declared before using the send http request action. When this built-in action is called, the multipart form data technique, provided by Rest Assured, is applied.
- To attach multiple files, in test procedures, call multiple attach file in sequence.
- control name:
- When a single file is attached, the value is optional. When this argument is empty, by default, the attach file action will assume a control name called file (learn more). Specifically, in HTML the control name is the attribute name of the input tag.
- To attach multiple files simultaneously, this argument is required. You must input a unique control name defined for each file attached.
- Please also note that, depending on the API-under-test, the value and availability of this argument might vary. Therefore, it is highly recommended that you read API documentations carefully. (See below)
- file name:
- When this value is empty, the default name for the attached file is file.
- Please also note that, depending on the API-under-test, the value and availability of this argument might vary. Therefore, it is highly recommended that you read API documentations carefully. (See below)
- On Windows: In order to specify mapping network drives, please disable User Account Control (UAC).
- On Linux, macOS: Mounted drives are supported.
- mime type:
- For a full list of available MIME types, refer to this site.
- When no MIME is provided, this argument is ignored during test automation.
- Please also note that, depending on the API-under-test, the value and availability of this argument might vary. Therefore, it is highly recommended that you read API documentations carefully. (See below)
- charset: Besides the standard charsets above, you can also manually enter other encoding sets. (Learn more)