-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.js
81 lines (61 loc) · 1.87 KB
/
upload.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
fs = require('fs');
request = require('request');
path = require('path');
function walk(currentDirPath, callback) {
fs.readdirSync(currentDirPath).forEach(function(name) {
var filePath = path.join(currentDirPath, name);
var stat = fs.statSync(filePath);
if (stat.isFile()) {
callback(filePath, stat);
} else if (stat.isDirectory()) {
walk(filePath, callback);
}
});
}
var files = [];
walk('./out', function(filename) {
//console.log(filename)
files.push(filename);
});
//console.log(JSON.stringify(files, null, 2))
//var i = parseInt(fs.readFileSync('last') + '');
var i = 0;
function next() {
var filename = files[i];
i++;
console.log('reading file ' + filename)
request({
method: 'POST',
//url: 'http://biocad.ncl.ac.uk:3030/igem/upload',
url: 'http://localhost:8890/sparql-graph-crud-auth/?graph-uri=https://synbiohub.org/public',
//url: 'http://synbiohub.org:8080/openrdf-sesame/repositories/synbiohub/statements',
auth: {
user: 'dba',
pass: 'dba',
sendImmediately: false
// pass: 'nyr-Dbt-roh-QW3',
},
/*qs: {
'context': 'null'
},*/
headers: {
//'Content-Type': 'multipart/form-data'
'Content-Type': 'application/rdf+xml'
},
//formData: {
//file: fs.createReadStream(filename)
//}
body: fs.readFileSync(filename) + ''
}, function(err, response, body) {
console.log('submitted ' + filename + ' with err ' + err + ' and response ' + response.statusCode);
console.log(body)
if(err) {
console.log('error! ' + err);
} else {
fs.writeFileSync('last', i + '');
}
next();
//callback(null, body);
});
}
next();