A simple REST utility for uploading files to a Managed File Transfer server or other file based integration servers, SaaS or PaaS cloud applications.
This packages exposes a REST interface to upload to MFT SOAP WebServices or arbitrary HTTP form applications. The utility works with Oracle Managed File Transfer server and uses payload templates so easily extensible to other use cases.
Implemented
- SOAP inline XML or Binary base64 encoded data
- Upload to SOAP service using SOAP attachments (SwA)
- HTTP Formdata for upload to arbitray web apps
- Chaining of requests for upload and notify SOAP service use cases
- Custom payload templates using templatedir property
- Allow removal of passwords from the config file
- Support respfile argument for template development and improved debugging
Future use cases include the following:
- Upload to HTTP servers using MTOM attachments
It is assumed you have knowledge and a working MFT server installed such as Oracle MFT. The SOAP interface communicates with an MFT SOA or SOAP Source that must be configured on the MFT server that implements the MFT SOAP WSDL.
npm install mft-upload --save
node upload.js file=index.js [config=req.json | passwords= debug=
file: Required pointer to the file to be uploaded.
config: Optional points to the config file described below. Default location is $HOME/.mft/upload.json
passwords: Optional space delimited array of passwords substituted into the config or templates
The config file describes a request type and maximum file size at the root level. It also embedds and reuses the request type endpoint and authentication used by the HTTP Request package. A sample req.json shown below using Basic authentication is provided in the files folder. The request package supports many authentication types beyond what is shown below.
{
"type": "SOAP",
"maxsize": 20214400,
"request": {
"url": "http://HOSTNAME:7901/mftapp/services/transfer/SOAP2File",
"method": "POST",
"headers": { "Content-Type": "text/xml; charset=utf-8" },
"auth": { "user": "USERNAME", "pass": "PASSWORD" }
}
}
Following type support SOAP with Attachments.
{
"type": "WSA",
"maxsize": 5242880026214400,
"request": {
"uri": "http://HOSTNAME.com:7901/mftapp/services/transfer/SOAP2File",
"method": "POST",
"headers": {
"FileName": "",
"Content-Type": "multipart/related;type=\"text/xml\""
},
"multipart": [
{
"Content-Type": "text/xml;charset=UTF-8",
"auth": { "user": "USERNAME", "pass": "PASSWORD" }
},
{
"Content-Type": "application/octet-stream"
}
]
}
}
Config "template" allows user provided template using any file name or location.
{
"type": "SOAP",
"template": "my-payload", // template file is at "my-payload"
"request": {
"url": "http://localhost:7901/mftapp/services/transfer/SOAP2File",
"method": "POST",
"headers": { "Content-Type": "text/xml; charset=utf-8" },
"auth": { "user": "USERNAME", "pass": "PASSWORD" }
}
}
Config "templatedir" allows user provided template location of filename "-PAYLOAD"
{
"type": "SOAP",
"templatedir": "mytemplates", // template file is at "mytemplates/SOAP-PAYLOAD"
"request": {
"url": "http://localhost:7901/mftapp/services/transfer/SOAP2File",
"method": "POST",
"headers": { "Content-Type": "text/xml; charset=utf-8" },
"auth": { "user": "USERNAME", "pass": "PASSWORD" }
}
}
Illustrates chaining of requests using "cfgarr config array element for upload followed by a SOAP notification call.
{
"type": "SOAP",
"cfgarr": [
{ "config": "wsa.json", "file": "package.json"}
],
"request": {
"url": "http://HOSTNAME:7901/mftapp/services/transfer/SOAP2File",
"method": "POST",
"headers": { "Content-Type": "text/xml; charset=utf-8" },
"auth": { "user": "USERNAME", "pass": "PASSWORD" }
}
}
If a config argument is not provided, upload.js looks for one at ~/.mft/upload.json using process.argv[1].
getRequestConfig(process.argv, function(err, retargs, cfgfile, cfgjson) {
if (err) {
console.log(err);
process.exit(1);
}
args = retargs;
filepath = args.file;
reqOptions = cfgjson;
});
fileUpload(filepath, reqOptions, function(er, respcode, jsonbody, stats) {
if (er) {
console.log(er);
process.exit(1);
}
console.log('Response code is: ' +respcode);
console.log(stats.summary);
});
upload(process.argv, function(err, respcode, jcfg, stats) {
if (err) {
console.log('Upload Error: ' +err);
process.exit(1);
};
});
npm install chai
npm test
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Created: May 6, 2015
Dave Berry A.K.A (bigfiles)
ISC