Last active
January 14, 2019 12:25
-
-
Save eventhough/02e83f7887a7d0b4b206 to your computer and use it in GitHub Desktop.
React component for handling S3 file upload
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
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 did you figure out the ENDPOINT_TO_GET_SIGNED_URL??
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
what should
ENDPOINT_TO_GET_SIGNED_URL
be?