Index

React Native

  1. Install Android Studio
  2. Introduction
  3. Navigation
    1. StackNavigator
    2. Login
    3. DrawerNavigator
    4. Custom Drawer
    5. Image
  4. Formik and Apollo Client
  5. Image Upload
  6. Alert
  7. Keyboard Avoiding View

Image Upload


takePicture() {
  this.camera.capture().then(data => {
    console.log(data);
    PicturePath = data.path;
  }).catch(err => console.error(err));
}



storePicture() {
  console.log(PicturePath);
  if (PicturePath) {
  
    // Create the form data object
    var data = new FormData();
    data.append('picture', {
      uri: PicturePath,
      name'selfie.jpg',
      type: 'image/jpg'
    });

    // Create the config object for the POST
    // You typically have an OAuth2 token that you use for authentication
    const config = {
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type''multipart/form-data;',
         Authorization: 'Bearer ' + 'SECRET_OAUTH2_TOKEN_IF_AUTH'
      },
      body: data
    };

    fetch('https://postman-echo.com/post', config).then(responseData => {
      // Log the response form the server
      // Here we get what we sent to Postman back
      console.log(responseData);
    }).catch(err => { console.log(err); });
  }
}



storePicture() {
  console.log(PicturePath);
  if (PicturePath) {
  
    // Create the form data object
    var data = new FormData();
    data.append('picture', {
      uri: PicturePath,
      name'animal.jpg',
      type: 'image/jpg'
    });
    
    const query = `mutation{
            CreateAnimalImage {
              message              
            }
          }`
          
     data.append('query', query)
    // Create the config object for the POST
    // You typically have an OAuth2 token that you use for authentication
    const config = {
      method: 'POST',
      headers: {'Content-Tranfer-Encoding''multipart/form-data''Content-Type''application/graphql'}},
              withCredentials: true,
          },
      body: data
    };

    fetch(graphql, config).then(responseData => {
      // Log the response form the server
      // Here we get what we sent to Postman back
      console.log(responseData);
    }).catch(err => { console.log(err); });
  }
}