Skip to content

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

@waqasarshad

Description

@waqasarshad

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions