@@ -97,6 +97,11 @@ component accessors="true" {
9797 */
9898 property name = " queryParams" ;
9999
100+ /**
101+ * An array of files to upload for the request.
102+ */
103+ property name = " files" type = " array" ;
104+
100105 /**
101106 * Flag to throw on a cfhttp error.
102107 */
@@ -150,6 +155,7 @@ component accessors="true" {
150155 variables .queryParams = createObject ( " java" , " java.util.LinkedHashMap" ).init ();
151156 variables .headers = createObject ( " java" , " java.util.LinkedHashMap" ).init ();
152157 variables .headers .put ( " Content-Type" , " application/json" );
158+ variables .files = [];
153159 variables .requestCallbacks = [];
154160 variables .responseCallbacks = [];
155161 // This is overwritten by the HyperBuilder if WireBox exists.
@@ -521,6 +527,35 @@ component accessors="true" {
521527 return this ;
522528 }
523529
530+ /**
531+ * Attaches a file to the Hyper request.
532+ * Also sets the Content-Type as `multipart/form-data`.
533+ * Multiple files can be attached by calling `attach` multiple times before calling a send method.
534+ *
535+ * @name The name of the file being uploaded.
536+ * @path The absolute path to the file to be uploaded.
537+ * @mimeType An optional mime type to associate with the file.
538+ *
539+ * @return s The HyperRequest instance.
540+ */
541+ function attach (
542+ required string name ,
543+ required string path ,
544+ string mimeType
545+ ) {
546+ setBodyFormat ( " formFields" );
547+ setContentType ( " multipart/form-data" );
548+ var fileInfo = {
549+ name : arguments .name ,
550+ path : arguments .path
551+ };
552+ if ( ! isNull ( arguments .mimeType ) ) {
553+ fileInfo [ " mimeType" ] = arguments .mimeType ;
554+ }
555+ variables .files .append ( fileInfo );
556+ return this ;
557+ }
558+
524559 /**
525560 * A convenience method to set the Content-Type header.
526561 *
@@ -629,6 +664,7 @@ component accessors="true" {
629664 variables .queryParams = createObject ( " java" , " java.util.LinkedHashMap" ).init ();
630665 variables .headers = createObject ( " java" , " java.util.LinkedHashMap" ).init ();
631666 variables .headers .put ( " Content-Type" , " application/json" );
667+ variables .files = [];
632668 variables .requestCallbacks = [];
633669 variables .responseCallbacks = [];
634670 return this ;
@@ -662,11 +698,11 @@ component accessors="true" {
662698 return this ;
663699 }
664700
665- /**
666- * Clones the current request into a new HyperRequest.
667- *
668- * @return s A new HyperRequest instance cloned from this one.
669- */
701+ /**
702+ * Clones the current request into a new HyperRequest.
703+ *
704+ * @return s A new HyperRequest instance cloned from this one.
705+ */
670706 public HyperRequest function clone () {
671707 var req = new HyperRequest ();
672708 req .setInterceptorService ( variables .interceptorService );
@@ -684,6 +720,7 @@ component accessors="true" {
684720 req .setReferrer ( isNull ( variables .referrer ) ? javacast ( " null" , " " ) : variables .referrer );
685721 req .setHeaders ( variables .headers .clone () );
686722 req .setQueryParams ( variables .queryParams .clone () );
723+ req .setFiles ( duplicate ( variables .files ) );
687724 req .setThrowOnError ( variables .throwOnError );
688725 req .setClientCert ( isNull ( variables .clientCert ) ? javacast ( " null" , " " ) : variables .clientCert );
689726 req .setClientCertPassword (
0 commit comments