-
-
Save omofolarin/d9fd73b3aafc71d8d961947c68349ee5 to your computer and use it in GitHub Desktop.
React Native File upload using XMLHttpRequest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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