Last active
November 16, 2019 16:42
-
-
Save loujaybee/c6ac77e3c62f761b6d6d7f3bb14a26e3 to your computer and use it in GitHub Desktop.
A crude but working upload example
This file contains hidden or 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
import React, { Component } from "react"; | |
import axios from "axios"; | |
export default class extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
upload_file: null | |
}; | |
} | |
async upload(event) { | |
const formData = new FormData(); | |
formData.append("uploadedFile", event.target.files[0]); | |
const config = { headers: { "Content-Type": "multipart/form-data" } }; | |
const data = await axios.post("https://yourapi.com/upload/", formData, config); | |
} | |
render() { | |
return ( | |
<div> | |
<input | |
value={this.state.upload_file} | |
onChange={event => this.upload(event)} | |
accept=".png" | |
type="file" | |
/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment