在angular
中,我向正文添加了file's
,他们使用express
上传了它们。但是我真的很想再次将文件移出目录。
这是我发送请求的angular code
:
addSongFilesToServer(title, lrc, txt, thumb, mp3instrumental) {
let url = this._config.ServerWithApiUrl + "uploadFiles";
let body : FormData = new FormData();
body.append('txt', txt, "pitches.txt");
body.append('lrc', lrc, "lyric.lrc");
body.append('thumb', thumb, "thumbnail.png");
body.append('mp3instrumental', mp3instrumental, "instrumental.mp3");
this._config.headers.delete('Content-Type');
return this._http.post(url, body, { headers: this._config.headers })
.map(res => res.json()).catch(function(err){
throw err;
});
}
然后使用express
上传它们:
var Router = express.Router();
Router.post('/uploadFiles', (req, res) => {
var title = this.lastTitle;
var storage = multer.diskStorage({
destination: function (req, file, cb) {
var dir = "../songs/" + title;
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
cb(null, dir);
},
filename: function (req, file, cb) {
cb(null, file.originalname);
}
});
this.lastTitle = "";
var upload = multer({ storage : storage}).any();
upload(req,res,function(err){
if(err){
return res.status(500).send({
code: 500, message: 'could not upload file: ' + err, error: err });
}else {
return res.status(200).send({
code: 200, message: 'All files uploaded!', err: ""});
}
});
});
现在,我需要一种类似的方法来GET´ me all of the files into a
列出or variables. I need to get all of the files in one specific folder, which name would be
标题`。并把它们全部作为回应。
我该怎么办?