Skip to content

Instantly share code, notes, and snippets.

@linux08
Created November 4, 2018 23:36
Show Gist options
  • Save linux08/0589bd2d54478ebd1bfa9a1bff21f9aa to your computer and use it in GitHub Desktop.
Save linux08/0589bd2d54478ebd1bfa9a1bff21f9aa to your computer and use it in GitHub Desktop.
selectImage = async () => {
ImagePicker.showImagePicker(options, async (response) => {
if (response.didCancel) {
this.setState({ error: 'Image upload failed', loading: null });
} else if (response.error) {
this.setState({ error: 'Image upload failed', loading: null });
} else if (response.customButton) {
this.setState({ error: 'Image upload failed', loading: null });
} else {
const source = { uri: response.uri };
this.setState({
uploadStatus: true,
avatarSource: source,
uri: response.uri,
type: response.type,
name: response.fileName,
originalName: response.fileName
});
global.data = new FormData();
data.append('file', {
uri: response.uri,
type: response.type,
name: response.fileName,
originalname: response.fileName,
});
const config = {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
},
body: data,
};
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment