XHR: support typed arrays for request payloads

Summary:
Support `xhr.send(data)` for typed arrays.

**Test plan:** run UIExplorer example on iOS and Android.
Closes https://github.com/facebook/react-native/pull/11904

Differential Revision: D4425551

fbshipit-source-id: 065ab5873407a406ca4a831068ab138606c3361b
This commit is contained in:
Philipp von Weitershausen
2017-01-20 18:40:28 -08:00
committed by Facebook Github Bot
parent 116916b98d
commit 16bb6e87ba
11 changed files with 293 additions and 63 deletions

View File

@@ -38,6 +38,8 @@ const {
View,
} = ReactNative;
const XHRExampleBinaryUpload = require('./XHRExampleBinaryUpload');
const PAGE_SIZE = 20;
class XHRExampleFormData extends React.Component {
@@ -109,31 +111,7 @@ class XHRExampleFormData extends React.Component {
xhr.open('POST', 'http://posttestserver.com/post.php');
xhr.onload = () => {
this.setState({isUploading: false});
if (xhr.status !== 200) {
Alert.alert(
'Upload failed',
'Expected HTTP 200 OK response, got ' + xhr.status
);
return;
}
if (!xhr.responseText) {
Alert.alert(
'Upload failed',
'No response payload.'
);
return;
}
var index = xhr.responseText.indexOf('http://www.posttestserver.com/');
if (index === -1) {
Alert.alert(
'Upload failed',
'Invalid response payload.'
);
return;
}
var url = xhr.responseText.slice(index).split('\n')[0];
console.log('Upload successful: ' + url);
Linking.openURL(url);
XHRExampleBinaryUpload.handlePostTestServerUpload(xhr);
};
var formdata = new FormData();
if (this.state.randomPhoto) {