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

320
Vistas
Upload and display images on IPFS via nft.storage using javascript and php

I'm trying to read an image file and upload to IPFS using nft.storage API.

The code below works by converting the image to base64 string, but the nft.storage link only displays the string, not as an image as shown here -> https://bafkreihxiweiopz4pfmqtub5klhsq7wuu7wrw24inbrozbl7cshd4uaqxq.ipfs.dweb.link/

IF I decode the string, I could see the image. How to let IPFS display the image at the link?

<?php
    // image to string conversion
    $imagelink = file_get_contents($image_original_path); 
  
    // image string data into base64 
    $encdata = base64_encode($imagelink);

?>

<script>
document.getElementById("test").addEventListener("click", function() {
    
        jQuery.ajax({
            type: 'POST',
            url: 'https://api.nft.storage/upload',
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsIn...")
            },
            mimeType: 'multipart/form-data', // this too
            contentType: "image/png",
            cache: false,
            processData: false,
            data: "<?php echo $encdata; ?>",
            success: function(data) {
              console.log(data);
              process the JSON data etc
            },
            error: function(data) {
                console.log(data);
           } 
        });
});
</script>
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