Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda