Created
July 2, 2021 09:42
-
-
Save AllardQuek/9ac05cfb158e9bfd796e9e61557ac710 to your computer and use it in GitHub Desktop.
This file contains 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 from "react"; | |
import "react-dropzone-uploader/dist/styles.css"; | |
import Dropzone from "react-dropzone-uploader"; | |
const Uploader = () => { | |
const axios = require("axios").default; | |
const API_ENDPOINT = <<YOUR_API_ENDPOINT>> | |
const handleChangeStatus = ({ meta, remove }, status) => { | |
console.log(status, meta); | |
}; | |
const handleSubmit = async (files) => { | |
const f = files[0]; | |
// GET request: presigned URL | |
const response = await axios({ | |
method: "GET", | |
url: API_ENDPOINT, | |
}); | |
// PUT request: upload file to S3 | |
const result = await fetch(response.data.uploadURL, { | |
method: "PUT", | |
body: f["file"], | |
}); | |
}; | |
return ( | |
<Dropzone | |
onChangeStatus={handleChangeStatus} | |
onSubmit={handleSubmit} | |
maxFiles={1} | |
multiple={false} | |
canCancel={false} | |
inputContent="Drop A File" | |
styles={{ | |
dropzone: { width: 400, height: 200 }, | |
dropzoneActive: { borderColor: "green" }, | |
}} | |
/> | |
); | |
}; | |
<Uploader />; | |
export default Uploader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment