I have a web server that accepts images from a client, processes them, uploads them to S3, inserts inserts URLs into my mongoDB and finally sends the json result back to the client.
Working with a single image works as follows:
router.post("/upload", function(req, res){
var form = new multiparty.Form();
form.parse(req,function(err,fields,files){
s3.upload({
Key: filename,
Bucket: bucketname,
ACL: "public-read",
Body: fs.createReadStream(filepath)
}, function(err, data){
if(err)
Model.collection.insert({"name": "name", "url" : data.Location}, function(err, result){
if(err)
res.json({result: result})
})
})
})
})
This works very well since I just upload the file data to s3 -> when it is done, insert s3 output (url) into the database -> when it is done, send the mongo result as jsonarray to the client.
, html type=file name=images, images[i]. images.length . , jsonarray , S3 upload- > mongo, , .
:
- , S3, URL- (
[data.Location]). mongoDB jsonarray . , mongo S3. - , S3 mongoDB .
if (currentIndex = images.length), jsonarray. , , ( ).
s3, mongo, , s3 urls, filename .. jsonarray?
, !
user4950757