I want to use node to transfer files to other servers
has been implemented
using request or axios libraries, but I want to get the progress of the transfer
what should I do?
// request
let form = {
type:"zip",
file:file,
path:"/temp"
}
request.post({
url:url,
formData:form
},(err,res,body)=>{
if(err){
console.log(err)
return
}
console.log(body)
console.log("")
})
// axios
let fd = new FormData();
fd.append("type","zip")
fd.append("file", file)
function getHeaders(form) {
return new Promise((resolve, reject) => {
form.getLength((err, length) => {
if(err) { reject(err); }
let headers = Object.assign({"Content-Length": length}, form.getHeaders());
resolve(headers);
});
});
}
getHeaders(fd)
.then(function(headers){
axios.post(url, fd, {
headers:headers,
onUploadProgress:function(e){
console.log("0")
}
}).then(function(res){
console.log("")
})
})