Skip to content

Instantly share code, notes, and snippets.

@abachuk
Created June 26, 2017 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abachuk/4a8fdf290deb1100ea4ffb488e9bd186 to your computer and use it in GitHub Desktop.
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
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