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

243
Vistas
Network request failed on uploading multiple images in react native

I'm uploading images through fetch api. While uploading, if a single images is selected it works perfectly but if multiple images are selected it gives error [TypeError: Network request failed]. i have tried commenting initializeFlipper and looked this answer also. Server takes array of images.. this is how images[] looks like when multiple images are selected

[{"height": 900, "mime": "image/jpeg", "modificationDate": "1649410153000", "path": "file:///data/user/0/com.emilio/cache/react-native-image-crop-picker/FB_IMG_1649005113656.jpg", "size": 78059, "width": 720}, {"height": 4160, "mime": "image/jpeg", "modificationDate": "1649410153000", "path": "file:///data/user/0/com.emilio/cache/react-native-image-crop-picker/IMG_20220330_134929_1.jpg", "size": 923567, "width": 1920}]

and this is how images looks like when single images is selected

[{"height": 725, "mime": "image/jpeg", "modificationDate": "1649410757000", "path": "file:///data/user/0/com.emilio/cache/react-native-image-crop-picker/FB_IMG_1649089342911.jpg", "size": 51443, "width": 720}]

this is my code:

  const postOrder = () => {
    var data = new FormData();
    data.append('marca', marca);
    data.append('modeo', modeo);
    data.append('option', option);
    data.append('description', description);
    data.append('images[]', {
      uri: images,
      name: 'image.jpg',
      type: 'image/jpeg',
    });
    data.append('userId', state.user.id);
    dispatch(saveOrder(data));
  };

export const saveOrder = data => dispatch => {
  console.log('/data in order action', data);
  fetch(`${baseUrl}/save-order`, {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'multipart/form-data',
    },
    body: data,
  })
    .then(res => res.json())
    .then(json => {
      console.log('json1', json);
      alert('order placed');
    })
    .catch(error => {
      console.log('error in saving', error);
    });
};

Edit checked with postman..multiple images are uploading successfully..this is how postman sending it. does anybody know how should i format images[] param postman

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

0

[TypeError: Network request failed] is thrown when the parameters you send are not correctly formatted. So try the other way I mentioned below.

Try doing a loop and append

images.map((file, index) => {
   data.append(`images[${index}]`, {
      uri: file,
      name: 'image.jpg',
      type: 'image/jpeg',
   });
})

Also, ask your backend developer to check if they are accepting the file in the correct param and way. Cross-check the same with the postman to confirm.

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