React Native File upload using XMLHttpRequest
_uploadSnap() {
var url = 'http://example.com/upload'; // File upload web service path
var photo = {
uri: this.state.picturePath, // CameralRoll Url
type: 'image/jpeg',
name: 'photo.jpg',
};
var formData = new FormData();
formData.append("file", photo);
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
console.log('OPENED', xhr.status);
xhr.onprogress = function () {
console.log('LOADING', xhr.status);
};
xhr.onload = function () {
console.log('DONE', xhr.status);
};
xhr.setRequestHeader('authorization', this.state.token);
xhr.send(formData);
}