MCPcopy Create free account
hub / github.com/ptmt/react-native-macos / _upload

Function _upload

Examples/UIExplorer/js/XHRExample.android.js:298–343  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

296 }
297
298 _upload() {
299 var xhr = new XMLHttpRequest();
300 xhr.open('POST', 'http://posttestserver.com/post.php');
301 xhr.onload = () => {
302 this.setState({isUploading: false});
303 if (xhr.status !== 200) {
304 console.log(
305 'Upload failed',
306 'Expected HTTP 200 OK response, got ' + xhr.status
307 );
308 return;
309 }
310 if (!xhr.responseText) {
311 console.log(
312 'Upload failed',
313 'No response payload.'
314 );
315 return;
316 }
317 var index = xhr.responseText.indexOf('http://www.posttestserver.com/');
318 if (index === -1) {
319 console.log(
320 'Upload failed',
321 'Invalid response payload.'
322 );
323 return;
324 }
325 var url = xhr.responseText.slice(index).split('\n')[0];
326 console.log('Upload successful: ' + url);
327 };
328 var formdata = new FormData();
329 this.state.textParams.forEach(
330 (param) => formdata.append(param.name, param.value)
331 );
332 if (this.state.randomPhoto) {
333 formdata.append('image', {...this.state.randomPhoto, type:'image/jpg', name: 'image.jpg'});
334 }
335 xhr.upload.onprogress = (event) => {
336 console.log('upload onprogress', event);
337 if (event.lengthComputable) {
338 this.setState({uploadProgress: event.loaded / event.total});
339 }
340 };
341 xhr.send(formdata);
342 this.setState({isUploading: true});
343 }
344
345 render() {
346 var image = null;

Callers

nothing calls this directly

Calls 5

openMethod · 0.95
appendMethod · 0.95
sendMethod · 0.95
logMethod · 0.65
indexOfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…