Neellohit Senapati
Neellohit Senapati

Reputation: 1

How does one access the Clarifai API for local file uploads in React?

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

Answers (1)

Jeremy Faret
Jeremy Faret

Reputation: 326

Upvotes: 0

Related Questions