Created
November 4, 2018 23:37
-
-
Save linux08/2d97e35e44ed9e3118c33b6564786574 to your computer and use it in GitHub Desktop.
This file contains 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
upload = async () => { | |
this.setState({ | |
loading: true | |
}); | |
if (!this.state.uploadStatus) { | |
this.setState({ loading: null }) | |
return alert('Image yet to be uploaded') | |
} | |
if (this.state.label === '') { | |
this.setState({ loading: null }) | |
return alert('Enter image label') | |
} | |
else { | |
data.append('label', this.state.label); | |
const config = { | |
method: 'POST', | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'multipart/form-data', | |
}, | |
body: data, | |
}; | |
fetch('http://10.0.2.2:5000/upload', config) | |
.then((resp) => resp.json()) | |
.then((res) => { | |
this.setState((prevState) => ({ | |
label: res.label, | |
hash: res.ipfsHash, | |
address: res.ipfsAddress, | |
transactionHash: res.transactionHash, | |
blockHash: res.blockHash, | |
loading: false, | |
images: prevState.images.concat(res), | |
})) | |
}) | |
.catch((err) => { | |
this.setState({ | |
loading: false, | |
error: err.message | |
}); | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment