Support File Arrays

Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
This commit is contained in:
Frank Jogeleit 2023-11-30 14:07:10 +01:00
parent 25a5a55111
commit 6f415ec7c5
5 changed files with 2788 additions and 13 deletions

View file

@ -123,21 +123,31 @@ jobs:
- name: Create Test File
run: |
echo "test" > testfile.txt
echo "test" > testfile1.txt
echo "test" > testfile2.txt
- name: Request Postman Echo POST Multipart
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
files: '{ "file": "${{ github.workspace }}/testfile1.txt" }'
- name: Request Postman Echo POST Multipart File Array
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
files: '{ "file": ["${{ github.workspace }}/testfile1.txt", "${{ github.workspace }}/testfile2.txt"] }'
- name: Request Postman Echo POST and persist response
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
file: "${{ github.workspace }}/testfile.txt"
file: "${{ github.workspace }}/testfile1.txt"
responseFile: "${{ github.workspace }}/response.json"
- name: Output responseFile
run: |
@ -148,14 +158,14 @@ jobs:
with:
url: 'https://postman-echo.com/post'
method: 'POST'
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
files: '{ "file": "${{ github.workspace }}/testfile1.txt" }'
- name: Request Postman Echo POST single file
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
file: "${{ github.workspace }}/testfile.txt"
file: "${{ github.workspace }}/testfile1.txt"
- name: Request Postman Echo POST URLEncoded string data
uses: ./

8
dist/index.js vendored
View file

@ -26660,7 +26660,7 @@ const convertToJSON = (value) => {
*
* @returns {FormData}
*/
const convertToFormData = (data, files, convertPaths) => {
const convertToFormData = async (data, files, convertPaths) => {
const formData = new FormData();
for (const [key, value] of Object.entries(data)) {
@ -26668,7 +26668,11 @@ const convertToFormData = (data, files, convertPaths) => {
}
for (const [key, value] of Object.entries(files)) {
formData.append(key, fs.createReadStream(value));
if (Array.isArray(value)) {
value.forEach(v => formData.append(key, fs.createReadStream(v)))
} else {
formData.append(key, fs.createReadStream(value));
}
}
return formData;

2761
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,9 @@
"yargs": "^17.7.2"
},
"dependencies": {
"@actions/core": "^1.10.1"
"@actions/core": "^1.10.1",
"install": "^0.13.0",
"npm": "^10.2.4"
},
"engines": {
"node": ">=16.0.0"

View file

@ -24,7 +24,7 @@ const convertToJSON = (value) => {
*
* @returns {FormData}
*/
const convertToFormData = (data, files, convertPaths) => {
const convertToFormData = async (data, files, convertPaths) => {
const formData = new FormData();
for (const [key, value] of Object.entries(data)) {
@ -32,7 +32,11 @@ const convertToFormData = (data, files, convertPaths) => {
}
for (const [key, value] of Object.entries(files)) {
formData.append(key, fs.createReadStream(value));
if (Array.isArray(value)) {
value.forEach(v => formData.append(key, fs.createReadStream(v)))
} else {
formData.append(key, fs.createReadStream(value));
}
}
return formData;