Last active
April 14, 2021 00:16
-
-
Save sam-ngu/cf7acab50c9a3b54aa75d2d2d7c411e8 to your computer and use it in GitHub Desktop.
Revisions
-
sam-ngu revised this gist
Apr 8, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,8 @@ for (let key in payload) { if (Array.isArray(value)) { value.forEach((item, index) => { // pack array content in FormData using the append method // first argument is the key, and the second argument is the value // the form data key should look something like: 'recipients[0]', 'recipients[1]' formData.append(`${key}[${index}]`, item); }); -
sam-ngu revised this gist
Apr 8, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ // payload to send in the API request const payload = { email: "[email protected]", recipients: [ '[email protected]', '[email protected]', ], attachment: fileObject, } // creating a new FormData instance @@ -17,6 +17,8 @@ for (let key in payload) { if (Array.isArray(value)) { value.forEach((item, index) => { // pack array content in FormData // the form data key should look something like: 'recipients[0]', 'recipients[1]' formData.append(`${key}[${index}]`, item); }); } else { -
sam-ngu revised this gist
Apr 8, 2021 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,9 @@ const payload = { email: "[email protected]", recipients: [ '[email protected]', '[email protected]', ], attachment: fileObject, } @@ -13,9 +16,8 @@ for (let key in payload) { let value = payload[key]; if (Array.isArray(value)) { value.forEach((item, index) => { formData.append(`${key}[${index}]`, item); }); } else { formData.append(key, value); -
sam-ngu created this gist
Feb 23, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ const payload = { email: "[email protected]", attachment: fileObject, } // creating a new FormData instance const formData = new FormData(); for (let key in payload) { let value = payload[key]; if (Array.isArray(value)) { const valueKey = key; value.forEach((item, index) => { formData.append(`${valueKey}[${index}]`, item); }); } else { formData.append(key, value); } }