An uploader module to upload all files in a directory or to upload files of a type. It sends a multipart request to the endpoint with all files attached to it
npm install dir-uploader- Technology stack: This is a npm module written in Vanilla JS.
- Status: This is the first functional version of this module. We are planning to add a change log starting from the next version
dir-uploader as a dependency in your package.json pointing to its current repo ``bash`
npm install dir-uploader --save-dev
To update to the latest version
`bash`
npm update dir-uploader
`
url: The URL of REST end point where we post the filesresult-path: the folder or file that need to be posted
metadata-file: meta data file that need to be posted
export-file-type: file type you want uploaded or true for all files in directory
delete-files: do we want to delete folder files after successfully sending the files
`Usage
You can use it using a commandline or inside another JS file as an import.
$3
From Command line you can either
- create and use send-data npm task
- or directly call export function sendDataUsing send-data npm task:
package.json script line would look like this
`
"send-data": "node -e 'require(\"dir-uploader\").sendData()'"
`At command prompt:
`
npm run send-data -- url='http://localhost:9456/resultmultipartupload' result-path='_test-reports/e2e-test-results/browser-based-results_2020-01-15T17_04' metadata-file='_test-reports/e2e-test-results/browser-based-results_2020-01-15T17_04/metadata.json' export-file-type=xml delete-files=false
`Using js exported function sendData:
`
node -e 'require("./dir-uploader").sendData("http://localhost:3020/post","tests/e2e/sample-exports/browser-based-results","tests/e2e/sample-exports/test.json",false,true)'
`$3
Similarly you can also upload multiple directory using a command like
`
node -e 'require("./dir-uploader").sendMultiFolderData("http://localhost:3020/post","tests/e2e/sample-exports/browser-based-results",'metadata.json', false, 'xml', 'tests')'
`You can also see an example of how to use module with single and multiple file upload options in the tests folder "runTests.js" file. These are e2e tests for this module. You can run them using the instructions given in the below section
How to test the software
This module includes a tests folder that contains a simple node test app, unit tests and end to end(e2e) tests. The tests runner is mocha (https://mochajs.org/). To run the tests
1. Firstly, install all the dependencies by npm install.
2. Go into testapp dir cd tests/testapp and run npm install to install testApp dependencies.
3. It is easier to run when you install mocha as a global dependency npm i -g mocha
4. Start the node test app node tests/testapp/server.js (tested on node v13).
5. Run the tests mocha tests/runTests.js`