我想使用 nodejs 将多个文件发送到 git 存储库。仅移动单个文件。当循环它的抛出错误时,例如在将标头发送到客户端后无法设置标头。下面是我的代码。建议我哪里做错了。
var base64 = require('file-base64');
for (var i in files) {
console.log('file load: ' + files[i]);
base64.encode('/opt/zipoutput/' + files[i], function (err, base64String) {
convertval = base64String;
var dataObj = {
"branch": "master",
"commit_message": "dump message",
"actions": [
{
"action": "create",
"file_path": files[i],
"content": convertval,
"encoding": "base64"
}
]
};
var filesrc = files;
var Client = require('node-rest-client').Client;
var client = new Client()
var args = {
data: dataObj,
headers: { 'Content-Type': 'application/json', 'PRIVATE-TOKEN': 'xxxxxxxxxxxxxxxx' },
};
client.post("https://gitlab.com/api/v4/projects/77/repository/commits", args, function (data, response) {
fs.rename('/opt/zipoutput/'+files[i], '/opt/sentFiles/'+files[i], function(err) {
if (err) throw err;
console.log("args passed:",args);
console.log("successfully moved into Sent file dirctory");
});
console.log("file send: True");
res.send("true");
});
});