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

145
Vistas
Get filereader result in nextjs Image

I'm trying to implement image preview before file upload in NextJs. When I read the result and try to display it doesn't work as usual. The image breaks. I have added the code below. Any inputs appreciated to sort this problem.

Edit: Partially solved this by converting the buffer to blob url. It works perfectly with img tag but next/image still doesn't support blob urls.

code

import React, { useCallback } from 'react';
import { useDropzone } from 'react-dropzone';
import Image from 'next/image';
import australia from '../public/images/australia.png';

const Create: React.FC<{ onClose: () => void }> = ({ onClose }) => {
    
    const [uploadedImage, setUploadedImage] = React.useState<any>();
    
    const onDrop = useCallback(acceptedFiles => {
        acceptedFiles.forEach((file) => {
            const reader = new FileReader()
    
            reader.onabort = () => console.log('file reading was aborted')
            reader.onerror = () => console.log('file reading has failed')
            reader.onload = () => {
                // Do whatever you want with the file contents
                const binaryStr = reader.result
                //changed this to blob url working perfectly with img tag not with Image tag.
                setUploadedImage(URL.createObjectURL(file));
                }
                reader.readAsArrayBuffer(file)
            })
        }, []);
    return (
            <>
               <div {...getRootProps()} className="p-7 border-2 border-dashed my-5 focus:border-indigo-500">
                <input {...getInputProps()} />
                {
                    isDragActive ?
                        <p>Drop the files here...</p> : <p>Drag 'n' drop some files here, or click to select files</p>
                }
                </div>
                <img src={uploadedImage || '/images/australia.png'} />
            </>
    );

Error Console error description after image upload

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