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

91
Visualizações
Amazon pre-signed url not displaying in image tag

I have a form that uploads an image to S3 and am trying to display the image to the user after it's been uploaded. After uploading the image I get a pre-signed url using the following code.

export const getUrlFromPath = async (filePath) => {
  filePath = splitUrl(filePath);
  const bucketPath = `${process.env.S3_UPLOAD_BUCKET}`;
  const s3Params = {
    Bucket: bucketPath,
    Key: filePath,
  };
  const command = new GetObjectCommand(s3Params);
  try {
    const signed = await getSignedUrl(s3Client, command, { expiresIn: 30 });
    return signed;
  } catch (e) {
    console.log(e);
  }
  return null;
};

I pass that url into my image tag expecting to see the image but it's not working. I have verified the image is uploaded properly and the url is valid. If I go to the url in the browser the image displays fine. I have also verified that correct url is in the image tag.

I have rendered the image tag in pug using the following:

 .col-md-4
    #file-preview-wrapper.big-bordered-wrapper.d-none
      p
        | Document Preview
        a#remove-file.text-danger.float-end(href="#") Remove
      img.d-none.full-width(src="" id="img-preview")
      embed.d-none.full-width(src="" id="pdf-preview" height="400" type="application/pdf")

And the following javascript updates the url with the signed url after an api call

  const previewUrl = (url) => {
    pdfPreview.src = "";
    imgPreview.src = "";
    previewWrapper.classList.add("d-none");
    if (url === "") {
      return;
    }

    previewWrapper.classList.remove("d-none");

    if (url.match(/pdf/)) {
      pdfPreview.src = url;
      pdfPreview.classList.remove("d-none");
    } else {
      imgPreview.src = url;
      imgPreview.classList.remove("d-none");
    }

    formSubmit.disabled = false;
  };
about 4 years ago · Juan Pablo Isaza
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