src/Context/ApiContext.php
public function setRequestBodyToFileResource($path) {
        if (!file_exists($path)) {
            throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path));
        }

        if (!is_readable($path)) {
            throw new InvalidArgumentException(sprintf('File is not readable: "%s"', $path));
        }

        // Set the Content-Type request header and the request body
        return $this
            ->setRequestHeader('Content-Type', mime_content_type($path))
            ->setRequestBody(fopen($path, 'r'));
    }
public function setRequestBodyToFileResource($path) {
        if (!file_exists($path)) {
            throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path));
        }

        if (!is_readable($path)) {
            throw new InvalidArgumentException(sprintf('File is not readable: "%s"', $path));
        }

        // Set the Content-Type request header and the request body
        return $this
            ->setRequestHeader('Content-Type', mime_content_type($path))
            ->setRequestBody(fopen($path, 'r'));
    }
public function setRequestBodyToFileResource ( $ path ) { if ( ! file_exists ( $ path ) ) { throw new InvalidArgumentException ( sprintf ( 'File does not exist: "%s"' , $ path ) ) ; } if ( ! is_readable ( $ path ) ) { throw new InvalidArgumentException ( sprintf ( 'File is not readable: "%s"' , $ path ) ) ; } // Set the Content-Type request header and the request body return $ this -> setRequestHeader ( 'Content-Type' , mime_content_type ( $ path ) ) -> setRequestBody ( fopen ( $ path , 'r' ) ) ; }
Set the request body to a read-only resource pointing to a file

This step will open a read-only resource to $path and attach it to the request body. If the
file does not exist or is not readable the method will end up throwing an exception. The
method will also set the Content-Type request header. mime_content_type() is used to get the
mime type of the file.

@param string $path Path to a file
@throws InvalidArgumentException
@return self

@Given the request body contains :path
Set the request body to a read - only resource pointing to a file