Skip to content

Instantly share code, notes, and snippets.

@eventhough
Last active January 14, 2019 12:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eventhough/02e83f7887a7d0b4b206 to your computer and use it in GitHub Desktop.
Save eventhough/02e83f7887a7d0b4b206 to your computer and use it in GitHub Desktop.
React component for handling S3 file upload
var React = require('react');
var Dropzone = require('react-dropzone');
var axios = require('axios');
exports = module.exports = React.createClass({
_onDrop: function (files) {
var file = files[0];
axios.get(ENDPOINT_TO_GET_SIGNED_URL, {
filename: file.name,
filetype: file.type
})
.then(function (result) {
var signedUrl = result.data.signedUrl;
var options = {
headers: {
'Content-Type': file.type
}
};
return axios.put(signedUrl, file, options);
})
.then(function (result) {
console.log(result);
})
.catch(function (err) {
console.log(err);
});
},
render: function () {
return (
<Dropzone onDrop={ this._onDrop } size={ 150 }>
<div>
Drop some files here!
</div>
</Dropzone>
);
}
});
@raptox
Copy link

raptox commented Jun 1, 2017

what should ENDPOINT_TO_GET_SIGNED_URL be?

@Ankita35
Copy link

@raptox did you figure out the ENDPOINT_TO_GET_SIGNED_URL??

@sholadedokun
Copy link

@raptox and @anika35 ENDPOINT_TO_GET_SIGNED_URL is the URL you are sending the file for processing... mostly likely a PHP or Node server.

@cabe56
Copy link

cabe56 commented Jan 22, 2018

The ENDPOINT_TO_GET_SIGNED_URL is the endpoint (in your server) where you return the signed URL that will be used in the call at line #22.

Checkout this article by the author, it uses this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment