-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientMTOM.js
54 lines (46 loc) · 1.6 KB
/
clientMTOM.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const soap = require('soap');
const fs = require('fs');
const path = require('path');
const url = 'http://localhost:8000/wsdl?wsdl';
function uploadMedia(filename) {
soap.createClient(url, {mtom:true}, function(err, client) {
if (err) {
console.error(err);
return;
}
const filePath = path.join(__dirname, filename);
const data = fs.readFileSync(filePath, 'binary'); // Read as binary
const args = { filename: filename, data: data };
client.UploadMedia(args, function(err, result) {
if (err) {
console.error(err);
return;
}
console.log(`Upload result for ${filename}:`, result.success);
});
});
}
function downloadMedia(filename) {
soap.createClient(url, {mtom:true}, function(err, client) {
if (err) {
console.error(err);
return;
}
const args = { filename: filename };
client.DownloadMedia(args, function(err, result) {
if (err) {
console.error(err);
return;
}
if (result.data) {
const filePath = path.join(__dirname, 'downloaded_' + filename);
fs.writeFileSync(filePath, result.data, 'binary'); // Write as binary
console.log(`Downloaded ${filename} to ${filePath}`);
} else {
console.log(`Download failed for ${filename}`);
}
});
});
}
uploadMedia('test.jpg'); // Place test.jpg in the same directory as clientMTOM.js
downloadMedia('test.jpg');