Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
A post method is working fine with Postman but not working in react native and getting error code 400. The api working from asp rest api.

I have tried this code.

What I have tried:

const formData = new FormData();
    formData.append("file", {
      uri: imageUri,
      name: stdAdmNo.replaceAll("/", ""),
      fileName: stdAdmNo.replaceAll("/", ""),
      type: "image/jpg",
    console.log("image detail", formData);
    let url = url;
    try {
        method: "post",
        url: url,
        data: formData,
        headers: {
          "Content-Type": "multipart/form-data",
        .then(() => {
          Alert.alert("Profile picture is successfully saved.");
        .catch((error) => {
    } catch (e) {
Updated 31-Aug-22 8:11am
Afzaal Ahmad Zeeshan 31-Aug-22 17:18pm    
Best is to debug why the request is returning a 400; maybe on the server-side. Perhaps, you missed to provide some headers or the body to the request?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900