1

after edit image data

after called api, image not inserted

can't upload images from react-native code to PHP codeIgniter server, however images are uploaded without any problem using postman,Other data is editable but image not upload from the react native application.so please could you tell me where exactly the problem is.

import React from "react";
import ProgressLoader from "../components/ProgressLoader";
import ImagePicker from "react-native-image-picker";

export default class ProfileContainer extends React.PureComponent {
  constructor(props) {
    super(props);
  }
  updateProfile() {
        const data = new FormData();
        data.append("user_id", parseInt(userObj.UserID) || 0);
        if (
          this.state.ImageSource != undefined &&
          this.state.ImageSource != null &&
          this.state.ImageSource != "" 

        ) {
          const fileType = "jpg";
          data.append("image",JSON.stringify({
            uri: this.state.ImageSource,
            name: `testPhotoName.${fileType}`,
            type: `image/${fileType}`
          }));
        }
        data.append("token", userObj.PhoneNumber);
        data.append("first_name", "" + this.state.firstName);
        data.append("last_name", "" + this.state.lastName);
        data.append("password", "1234");
        data.append("notification", this.state.isNotification ? "1" : "0");


        alert("with edit Profile Data------>"+JSON.stringify(data));

        fetch('http://freshnme.shreeduttply.com/v1/api/editProfile', {
            method: 'POST',
            headers: {
              'Accept': 'application/json',
              'Content-Type': 'multipart/form-data'
            },
            body: data })
          .then((response) => response.json())
          .then((responseJson) => {
              alert("After Called Api response:  " + JSON.stringify(responseJson));
          })
          .catch((error) => {
              console.error(error);
          });```
Dipika
  • 39
  • 1
  • 1
  • 5

0 Answers0