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

205
Visualizações
JS share: Get image from object

i am working on a script where users can share content using the native Javascript Share API.

title, text, URL and an image file (blob).

But i want to add an intermediate step where i first show the data (including the image) to the user and then - after click on "share now" - call the share API itself.

Therefore i also want to show a preview of the image file in the share object.

But i wonder how i can get the Blob() out of the filesArray and show it in the frontend to the user...

This is what i tried:

function sharePreview(data) {
  
        let code = "";
        
            if(data.title != undefined) {
                code += "<strong>"+data.title+"</strong><br />";
            }
            
            if(data.text != undefined) {
                code += data.text+"<br />";
            }
            
            if(data.url != undefined) {
                code += "URL: "+data.url+"<br />";
            }
            
            if(data.files != undefined) {
        code += "Image: ???<br />"
                console.log("Files: ", data.files[0]);
            }
            
        let btn = document.createElement("button");
        btn.classList.add("button");
        btn.innerText = "share Now";
            
        let l = document.getElementById('layer');
    l.innerHTML = code;
        
        l.appendChild(btn);
        
        btn.addEventListener("click", function() {
        
                try {
                    navigator.share(data);
                }
                catch(err) {
                    console.log("Teilen fehlgeschlagen. "+err);
                }
        });
  
}

https://codepen.io/kili123/pen/dymPBKr

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