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

100
Visualizações
Deleting from s3 bucket and database. Run one function after another

I'm trying to run an API call that deletes an image from an S3 bucket and MySQL db but running into an issue where the s3 image can't be found as it's being deleted from the database first.

// Router code:

//req.body is an array of ids. e.g. [ 213, 214]
//remove from s3

req.body.forEach((mediaId) => {
    mediaService.removeMediaItem(mediaId);
});


//remove from db

await recycleBinService.deleteRecycledMedia(req.body);

Ideally this code in the router runs delete from s3 > delete from db but currently I think it's deleting from db first as the image variable in the removeMediaItem function is showing as null if I log it out.

// removeMediaItem

const removeMediaItem = async (mediaId) => {
  const image = await _db.findOne("media", { id: mediaId });
  console.log("image: ", image);
  await s3Connection.deleteFile(image.file_name);
};
// deleteRecycledMedia

const wheresMedia = _apiDb.orWhere("id", mediaIds);
const wheresRecycle = _apiDb.orWhere("media", mediaIds);

// db Query that second input after first.

await _apiDb.doubleRawSql(
`DELETE from media ${wheresMedia}`,
`DELETE from recycle_bin ${wheresRecycle}`
  );
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to await removeMediaItem. i.e.

req.body.forEach((mediaId) => {
  await mediaService.removeMediaItem(mediaId);
}
about 4 years ago · Juan Pablo Isaza 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