attach file

Attach given file(s) to a web service.
NameDescriptionTypeModifier
path

Path to the location of the attached file.

StringNone
control name

Value of the name attribute in the HTML input tag. (see )

StringNone
file name

(Optional) Attach the given file with a new name.

StringNone
mime type

(Optional) MIME type of the attached file.

StringNone
charset

(Optional) The character set (character encoding) to use.

Standard charset values:

  • US-ASCII or ISO646-US

    Seven-bit ASCII, a.k.a. the Basic Latin block of the Unicode character set.

  • ISO-8859-1

    ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.

  • UTF-8

    Eight-bit UCS Transformation Format.

  • UTF-16BE

    Sixteen-bit UCS Transformation Format, big-endian byte order.

  • UTF-16LE

    Sixteen-bit UCS Transformation Format, little-endian byte order.

  • UTF-16

    Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark.

Value SetUS-ASCII, ISO646-US, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16
None
This action may be used within the following project items: test modules and user-defined actions.
The following settings are applicable to this action: remove double quotes from cells.
Uploading Files With Real World Examples
  1. 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
                          
                      
  2. 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
                          
                      
  3. 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			
      &nbsp					
      	path	control name	file name	mime type	charset
      attach file	#cf local folder	json	file.png	application/json	UTF-8
                          
                      
  4. 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:

  1. Path to the location of the attached file: /Users/test/Desktop/TestData/Web Services/testfile.png
  2. Value of the name attribute in the HTML input tag: file
  3. Attach the given file with a new name: file.png
  4. MIME type of the attached file: image/png
  5. 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					
&nbsp					
	key	value			
add http parameter	path	\\192.168.167.41\Log\data			
&nbsp					
	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
&nbsp					
	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)

Copyright © 2024 LogiGear Corporation. All rights reserved. LogiGear is a registered trademark, and Action Based Testing and TestArchitect are trademarks of LogiGear Corporation. All other trademarks contained herein are the property of their respective owners.

LogiGear Corporation

1730 S. Amphlett Blvd. Suite 200, San Mateo, CA 94402

Tel: +1 (650) 572-1400