我试图创建文件并将它们放入文件夹,然后发送链接到Microsoft Emotion API。创建/重新加载node.js中的动态快速文件夹
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({limit: '4mb'}));
app.use('/pics', express.static(path.join(__dirname, 'pics')))
app.post('/face', function(req, res){
var base64Data = req.body.img.replace(/^data:image\/png;base64,/, "");
var id;
fs.readdir("./pics", (err, files) => {
id = files.length;
fs.writeFile(`./pics/${id}.png`, base64Data, 'base64', function(err) {
console.log(err);
reload(http, app);
setTimeout(function(){
fetch(`https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize`, {
method: "POST",
data: `{"url": "${"https://{ngrok-id}.ngrok.io/pics/"+id+".png"}"}`,
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '{api-key}'
}
}).then(function(data) {
return data.json();
}).then(function(data){
console.log(`{"url": "${"https://{ngrok-id}.ngrok.io/pics/"+id+".png"}"}`);
res.json(data);
});
}, 2000);
});
});
});
有没有办法让快递文件夹动态或重新加载静态文件夹?