node.js で SOAP ベースの Web サービスからファイルをダウンロードまたは処理する必要があります。誰かがnode.jsでこれを処理する方法について私に提案できますか
「node-soap」または「soap」NPM モジュールを試しました。通常の SOAP Web サービスで機能しました。ただし、バイナリ スチームまたは MTOM ベースの SOAP Web サービスではありません。
node.js で SOAP ベースの Web サービスからファイルをダウンロードまたは処理する必要があります。誰かがnode.jsでこれを処理する方法について私に提案できますか
「node-soap」または「soap」NPM モジュールを試しました。通常の SOAP Web サービスで機能しました。ただし、バイナリ スチームまたは MTOM ベースの SOAP Web サービスではありません。
これに答えてみたくて... 2年2ヶ月経っても同じ問題を簡単に解く方法がわからないというのはなかなか興味深いものです。
次のような応答から添付ファイルを取得しようとしています:
...
ヘッダー: { 'cache-control': 'no-cache="set-cookie"', 'content-type': 'multipart/related;boundary="----=_Part_61_425861994.1525782562904";type="application/ xop+xml";start="";start-info="text/xml"',
...
本体: ' ------=_Part_61_425861994.1525782562904\r\nContent-Type: アプリケーション/xop+xml; charset=utf-8; type="text/xml"\r\nContent-Transfer-Encoding: 8bit\r\nContent-ID: \r\n\r\n....\r\n------=_Part_61_425861994.1525782562904 \r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: binary\r\nContent-ID: \r\n\r\n�PNG\r\n\u001a\n\u0000\ u0000\u0000\rIHDR\u0000\u0000\u0002,\u0000\u0000\u0005�\b\u0006\u0....バイナリ....
ws.jsを試しましたが、解決策はありません。
私の解決策:
var request = require("request");
var bsplit = require('buffer-split')
// it will extract "----=_Part_61_425861994.1525782562904" from the response
function getBoundaryFromResponse(response) {
var contentType = response.headers['content-type']
if (contentType && contentType.indexOf('boundary=') != -1 ) {
return contentType.split(';')[1].replace('boundary=','').slice(1, -1)
}
return null
}
function splitBufferWithPattern(binaryData, boundary) {
var b = new Buffer(binaryData),
delim = new Buffer(boundary),
result = bsplit(b, delim);
return result
}
var options = {
method: 'POST',
url: 'http://bla.blabal.../file',
gzip: true,
headers: {
SOAPAction: 'downloadFile',
'Content-Type': 'text/xml;charset=UTF-8'
},
body: '<soapenv: ... xml request of the file ... elope>'
};
var data = [];
var buffer = null;
var filename = "test.png"
request(options, function (error, response, body) {
if (error) throw new Error(error);
if (filename && buffer) {
console.log("filename: " + filename)
console.log(buffer.toString('base64'))
// after this, we can save the file from base64 ...
}
})
.on('data', function (chunk) {
data.push(chunk)
})
.on('end', function () {
var onlyPayload = splitBufferWithPattern(Buffer.concat(data), '\r\n\r\n') // this will get from PNG
buffer = onlyPayload[2]
buffer = splitBufferWithPattern(buffer, '\r\n-')[0]
console.log('Downloaded.');
})
ほとんどの場合に機能するかどうかはわかりません。私の目には不安定なコードのように見えるので、もっと良いものを探しています。