私は私のインターフェイスのためkoajsを使用する私は、ファイルkoajsマルチパートフォームポスト、エキスのzip前に応答を送信
どのように我々は彼らがKOA前に、抽出された取得するこれらのファイルのループを行うことができますようにジッパーを添付xに1を持つフォームを持っています返信を送る:/?ここ
は、私が試したものをS(非常に悪いかもしれないので、ドントン非常によく理解して:P)
module.exports.add = function *() {
var results = {};
var doc = {};
var form = yield formidable.parse(this);
Iterator.iterate(doc.points).forEach(function (point, index) {
co(function *() {
var p = {}
p.km = point.km;
p.num = point.num;
var f = {};
var file = form.files['serie-'+p.num];
f.oPath = file.path;
f.name = file.name;
f.path = storageDir+'checkpoint/'+p.num;
f.size = file.size;
f.mime = file.type;
p.document = f;
yield extractZip(f)
console.log('after zip')
var files = yield analyseFiles(f)
console.log('after analyse ' + JSON.stringify(files))
var pt = new Point(p);
pointsList.push(p);
console.log("result after index : "+index, p)
});
});
// here i store my doc in rethinkdb... but it s posted directly it do not wait the zip extract anf file analysis :/
}
function* extractZip(file) {
console.log('in zip')
yield exec('mkdir -p ' + file.path+' && unzip -o '+file.oPath+' -d '+ file.path);
}
function* analyseFiles(file) {
console.log('in analyse')
var files = yield walk(file.path)
return files;
});
}
結果として、私は
<-- POST /courses/add
{ fields:
{ idCourseType: '3accf2c1-9424-438b-b970-abf328679fcd',
nom: 'trek de paris',
dateCourse: '2016-03-22',
heureDepartCourse: '08:15',
'km-serie-1': '2',
'km-serie-2': '4',
points: '%5B%7B%22id%22%3A%2220P38-G-5C1022-B91299%22%2C%22num%22%3A1%2C%22km%22%3A2%7D%2C%7B%22id%22%3A%2220O99-D-B99648-B91262%22%2C%22num%22%3A2%2C%22km%22%3A4%7D%5D' },
files:
{ 'serie-1':
File {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
size: 325558122,
path: '/tmp/upload_c62a80f7822cade622ffd1bddc8032b8',
name: 'photos.zip',
type: 'application/zip',
hash: null,
lastModifiedDate: Mon Mar 21 2016 17:01:07 GMT+0100 (CET),
_writeStream: [Object] },
'serie-2':
File {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
size: 325558122,
path: '/tmp/upload_1115a5eaf4a213c5307c3ccec9200d49',
name: 'photos.zip',
type: 'application/zip',
hash: null,
lastModifiedDate: Mon Mar 21 2016 17:01:08 GMT+0100 (CET),
_writeStream: [Object] } } } [ { id: '20P38-G-5C1022-B91299', num: 1, km: 2 },
{ id: '20O99-D-B99648-B91262', num: 2, km: 4 } ] '0726332b-bf00-4f8d-8bd3-3429ae0e2b13'
in zip
in zip
{ uuid: '0726332b-bf00-4f8d-8bd3-3429ae0e2b13',
points: model { list: [] },
nom: 'trek de paris',
date: '2016-03-22',
depart: '08:15',
idCourseType: '3accf2c1-9424-438b-b970-abf328679fcd',
totalPoints: 2 }
--> POST /courses/add 200 2,229ms 22.57kb
<-- GET /api/courses/types/list
--> GET /api/courses/types/list 200 7ms 209b
after zip
in analyse
after analyse {"list":[]}
result after index : 1 model {
km: 4,
num: 2,
document:
{ oPath: '/tmp/upload_1115a5eaf4a213c5307c3ccec9200d49',
name: 'photos.zip',
path: '/home/srv/sites/tranceandroute/2016/RO/0726332b-bf00-4f8d-8bd3-3429ae0e2b13/checkpoint/2',
size: 325558122,
mime: 'application/zip' } }
after zip
in analyse
after analyse {"list":[]}
result after index : 0 model {
km: 2,
num: 1,
document:
{ oPath: '/tmp/upload_c62a80f7822cade622ffd1bddc8032b8',
name: 'photos.zip',
path: '/home/srv/sites/tranceandroute/2016/RO/0726332b-bf00-4f8d-8bd3-3429ae0e2b13/checkpoint/1',
size: 325558122,
mime: 'application/zip' } }
などを持っている瞬間のためにあなたはループが終了する前に私は - > POST /コース/追加200 2,229ms 22.57kbを見ることができます
私は親愛な?
おかげ