Skip to content

Instantly share code, notes, and snippets.

@Tamal
Last active March 28, 2024 13:53
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save Tamal/9231005f0c62e1a3f23f60dc2f46ae35 to your computer and use it in GitHub Desktop.
Save Tamal/9231005f0c62e1a3f23f60dc2f46ae35 to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment