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

121
Vistas
Send object and list of image to server in Reactjs

I'm using Reactjs in frontend.

I've set the profilePicture to state with this code

    handleImageChange = (event) => {
        event.preventDefault();
        var file = event.target.files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);

        reader.onloadend = function (e) {
            this.setState({
                profilePicture: e.target.result //don't know how it is working 
            });
        }.bind(this);
    }

and I can preview the image file:

<img src={this.state.profilePicture} alt="img"/>

I want to send these data to server:

data = {
    'profilePicture': anImageFile,//this.state.profilePicture
    'photos': [anotherImage, anotherImage2, anotherImage3],
    'personal_info': {
        'name': 'User Name',
        'anyList': [1,2,3]
    }
}

Can I do it using fetch?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can simply do like this:

handleImageChange = (event) => {
        this.setState({profilePicture: event.target.files[0]});
    }

Render Func

<img src={URL.createObjectURL(this.state.profilePicture)} alt="img"/>

And send data object as it is

about 4 years ago · Juan Pablo Isaza Denunciar
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