Created
June 26, 2017 22:03
-
-
Save abachuk/4a8fdf290deb1100ea4ffb488e9bd186 to your computer and use it in GitHub Desktop.
upload files to custom node middleware and CDN, get response back in react.js
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'; | |
class uploadMyFile extends Component { | |
handleUploadFile = (event) => { | |
const data = new FormData(); | |
data.append('file', event.target.files[0]); | |
data.append('name', 'some value user types'); | |
data.append('description', 'some value user types'); | |
// '/files' is your node.js route that triggers our middleware | |
axios.post('/files', data).then((response) => { | |
console.log(response); // do something with the response | |
}); | |
render() { | |
<div> | |
<input type="file" onChange={this.handleUploadFile} /> | |
</div> | |
} | |
} | |
export default uploadMyFile; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment