Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

expo react native send image to api

async function takeAndUploadPhotoAsync() {
  // Display the camera to the user and wait for them to take a photo or to cancel
  // the action
  let result = await ImagePicker.launchCameraAsync({
    allowsEditing: true,
    aspect: [4, 3],
  });

  if (result.cancelled) {
    return;
  }

  // ImagePicker saves the taken photo to disk and returns a local URI to it
  let localUri = result.uri;
  let filename = localUri.split('/').pop();

  // Infer the type of the image
  let match = /.(w+)$/.exec(filename);
  let type = match ? `image/${match[1]}` : `image`;

  // Upload the image using the fetch and FormData APIs
  let formData = new FormData();
  // Assume "photo" is the name of the form field the server expects
  formData.append('photo', { uri: localUri, name: filename, type });

  return await fetch(YOUR_SERVER_URL, {
    method: 'POST',
    body: formData,
    headers: {
      'content-type': 'multipart/form-data',
    },
  });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery remove focus from all elements 
Javascript :: ajax onchange dropdown 
Javascript :: copy one array to another javascript 
Javascript :: cdn jquery 
Javascript :: flask return status code 200 and json 
Javascript :: LF would be replaced by CRLF in package-lock.json 
Javascript :: js array of objects get a specific key from all objects 
Javascript :: regex valid url 
Javascript :: count value a to b character javascript 
Javascript :: getting average of array javascript 
Javascript :: if classlist contains js 
Javascript :: smooth scroll safari 
Javascript :: calculate width of text javascript 
Javascript :: toast message angular 
Javascript :: does filter mutate array 
Javascript :: axios.post headers example 
Javascript :: data not write in file node js 
Javascript :: how to know if ajax is running 
Javascript :: change next js default port 
Javascript :: javascript round to 8 decimal places 
Javascript :: angular http loader 
Javascript :: js check if div have another div 
Javascript :: pipe data to json angular 
Javascript :: scrollto is not a function javascript 
Javascript :: how to change the color of a console.log in javascript 
Javascript :: array push method 
Javascript :: how to get last string in javascript 
Javascript :: angular directive output 
Javascript :: wordpress javascript localization 
Javascript :: get the data from selected item in select 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =