Reputation: 1
This is my first question in Stack Overflow in my developer journey. In my project, I have implemented a file upload system which on clicking the button would trigger the Clarifai API recognition. Below is a snippet of my code where the thing is happening. Unfortunately, it seems to me that the this.state.input
isn't updating in the right manner so that the API could respond. Any sort of help would be highly appreciated. Thank you.
handleImage = (e) => {
this.setState({input: URL.createObjectURL(e.target.files[0])});
}
onButtonSmash = () => {
this.setState({imageUrl: this.state.input});
app.models.predict(Clarifai.CELEBRITY_MODEL, this.state.input)
.then(response => this.setState({solution: response.outputs[0].data.regions[0].data.concepts})
.catch(err => console.log(err)))
}
<div>
<input type="file" onChange={this.handleImage} />
</div>
Upvotes: -1
Views: 126
Reputation: 326
Make sure you have initialized the API as such: https://github.com/Clarifai/clarifai-javascript#basic-use
Make sure that onButtonSmashed is called (looks nested in your code snippet)
Upvotes: 0