Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Upload large files to AWS s3 using express js synchrounsly

Currently i am using putObject to upload the large file to AWS s3 with REST api call.

 var params ={               
     Bucket:'lambdacushbu',    
     Key:req.files.image.name, 
     Body:req.files.image.data 
 }                             
  s3.putObject(params,function(err, data) {                      
      if (err) console.log(err, err.stack); // an error occurred      
      else     {                                                      
          console.timeEnd('Uploadtime');                              
          console.log("uploaded",data);                               
          res.json({                                                  
              'status':'Uploaded',                                    
              'url':data.Location                                     
          });                                                         
      }           // successful response                              
  });                                         

But its looks like asynchronous i want the above in synchronous mode also a timeout is occurred but the file is being uploaded to the AWS s3.

So how can i increase the timeout value?? tried with connect-timeout package

app.use(timeout('600000'));

But it dosen't worked

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try using upload function instead of putObject. That should solve your timeout problem.

Here is a documentation for that function: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property

Synchronous call will definitely lower your app's performance. Can you provide me more details about your problem so we can find an async solution?

EDIT: Here is how you should return response in your controller:

router.post('/your-route',
  //additional middlewares
  function(req, res, next) {
     var params = {               
      Bucket:'lambdacushbu',    
      Key:req.files.image.name, 
      Body:req.files.image.data 
      }                             
      s3.upload(params,function(err, data) {                      
        if (err) { res.json(err); }      
        else {                                                        
           res.json({                                                  
          'status':'Uploaded',                                    
          'url':data.Location                                     
       }
      });                                             
  }
);

And make sure you don't call res.json() or res.send() anywhere else in this route

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!