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

183
Vistas
Axios wont send image over form in React-Native

I have been chasing this bug for several days and finally found that it is axios. Why does fetch work to upload an image from React-Native to Django REST here:

export const uploadBusinessImage = createAsyncThunk(
  "business/uploadBusinessImage",
  async (imgPath, { rejectWithValue }) => {
    var formData = new FormData();
    formData.append("image", {
      uri: imgPath,
      name: "myfoto.jpg",
      type: "image/jpg",
    });
    const url = "http://10.0.0.241/api/upload/";
    fetch(url, {
      method: "POST",
      headers: {
        "Accept": "application/json",
        "Content-Type": "multipart/form-data",
      },
      body: formData,
    })
  }
);

but axios doesn't work here:

export const uploadBusinessImage = createAsyncThunk(
  "business/uploadBusinessImage",
  async (imgPath, { rejectWithValue }) => {
    try {
      var formData = new FormData();
      formData.append("image", {
        uri: imgPath,
        name: "myfoto.jpg",
        type: "image/jpg",
      });
      const response = await axiosInstance({
        method: "post",
        url: "/api/upload/",
        data: formData,
        headers: { 
          "Accept": "application/json",
          "Content-Type": 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
        },
      });
      console.log(response.data);
      return response.data;
    } catch (err) {
      console.log(err.response.data);
      return rejectWithValue(err.response.data);
    }
  }
);

It creates the object in the database as image: null

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