I looked at lot of example but couldn't achieve it..so need help..
Problem..
- the content from loop should be passed to execute one by one.
- each loop iteration contains a file read and database save operation along with few other object properties that need to be assigned.
I have created example here..
http://runnable.com/VI1efZDJvlQ75mlW/api-promise-loop-for-node-js-and-hello-world
how to run:
Api: http://web-91b5a8f5-67af-4ffd-9a32-54a50b10fce3.runnable.com/api/upload
method : POST
content-type : multipart/form-data
upload more than one file with name.
..
the final expected promise is
files.name = "name of file"
files.content
files.content-type
files.size
- saved to db.
currently i am getting different content from file..but other files content are not filled and is undefined.
Regards Moyeen
The technique you're looking for is thenable chaining
Basically, we tell each operation to happen after the previous one has finished by chaining them and
return
ing which causes a wait on the asynchronous value.As a byproduct you can later use
The handler will run when all the promises are done.
I have updated the code with Q.all as the mentioned p.then will execute only once.
http://runnable.com/VI1efZDJvlQ75mlW/api-promise-loop-for-node-js-and-hello-world
the question is how to use q.npost if i have mongoose model files and want to save...?