Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda