Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to upload image on server using axios in react native #101

Open
waqasarshad opened this issue Oct 31, 2023 · 1 comment
Open

unable to upload image on server using axios in react native #101

waqasarshad opened this issue Oct 31, 2023 · 1 comment

Comments

@waqasarshad
Copy link

i am trying to upload a image with my other text data to server. but text data is uploading but image never uploads. here is my code

const fileToUpload = selectedImage1;
      const data = new FormData();
      data.append('image', 'Image Upload');
      data.append('file_attachment', fileToUpload);

    fetch('URL', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      first_name: textInputFname,
      last_name: textInputLname,
      email: textInputEmail,
      password: textInputPassword,
      phone: textInputPhone,
      address: textInputAddress,
      type: checked=='first'?1:2,
      company_name: textInputCoName,
      company_address: textInputCoAddress,
      company_tax_number: textInputCoTaxNum,
      extra_info: textInputExtraInfo,
      image: data
      })
  }).then((response) => response.json())
@waqasarshad
Copy link
Author

waqasarshad commented Oct 31, 2023

selectedImage1 is the image path that i selected from image picker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant