Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda