I am new to node js / express. I am trying to make several applications for downloading images with a cloud and s3 bucket. And I want to show a progress bar for the user. I use the io.Photo uploading progress socket for this to be in loop.but the problem is when the photo upload starts, it always shows 100% completion not from the very beginning. I donβt think the download is complete, itβs not, My file is 20 MB. I do not what happened Something
this is my code
app.post('/posttodb',(req,res) => { let isLoggedIn = req.cookies['check']; let token = req.cookies['peace']; const bucketName = 'awsBucketName'; console.log(isLoggedIn); if(isLoggedIn == "true"){ if(token){ jwt.verify(token,JWTPASS,(err,decode) => { if(err){ console.log(err) res.json({error:true}) }else{ console.log('========================>',decode) let postOwneranme = decode.user.username; let postTags = req.body.data.postTags; let photosBlob = req.body.data.photos; let postId = req.body.data.postId; let nepostAwsPhots = []; let OwnerPic = decode.user.propic; let postOwnerFullName = decode.user.name; let isMature = req.body.data.isMature; let postThumbUrl = req.body.data.thumnailUrl; let time = new Date(); let tagSlug = req.body.data.tagSlug; function savetodb() { console.log('Inserting all into DB'); r.connect({db:'image'}).then(conn => { r.table('posts').insert({postId:postId,username:postOwneranme,tag:postTags,postUrlsAndCaptions:nepostAwsPhots,comments:[],postOwnerPic:OwnerPic,likesCount:0,whoLikedIt:[],views:0,postedTime:time,postOwnerFullName:postOwnerFullName,isMature:isMature,thumNailUrl:postThumbUrl,tagSlug:tagSlug}).run(conn).then(response => { console.log(response) if(response.inserted > 0){ console.log('Done Bro') res.json({okva:true,postId:postId,username:postOwneranme}) }else{ res.json({okva:false}) } }) }) } function seemsToHaveNetworkProblem() { res.json({okva:false,message:"Seems To Have Network Problem"}) } forEachOf(photosBlob,(value,key,callback) => { console.log(value.id); let newImageUriWillBe = value.blobData; let newImageNamewillBe = value.id; let imageType = value.ImageType; let caption = value.caption; console.log(imageType) let buf = new Buffer(newImageUriWillBe.replace(/^data:image\/\w+;base64,/, ""),'base64'); s3.createBucket({Bucket:bucketName},() => { let params = {Bucket: bucketName, Key: postOwneranme+'/'+newImageNamewillBe, Body: buf,ContentType:imageType,ContentLength:buf.length,ACL:'public-read'}; s3.upload(params,(err,data) => { if(err){ callback(err); }else{ // console.log("Successfully uploaded data to " + bucketName + "/" + id); // console.log(`https:`); let response = { picUrl:`https:`, cation:caption } nepostAwsPhots.push(response); callback() // console.log(nepostAwsPhots) res.writeHead(200, {'content-type': 'text/plain'}); res.end('Ok'); } }) //Problem Comes here .on('httpUploadProgress', function(evt) { let per = Math.round((evt.loaded * 100) / evt.total) console.log('Progress:',per); Socket.emit('Scoket',{proccesing:per}) }) }); },(err) => { if(err){ console.log("From Node Loop error",err); seemsToHaveNetworkProblem() }else { savetodb() } }) } }) }else { res.json({error:true}); console.log('OMG') } }else{ res.json({error:true}); console.log('OMG') } });