Skip to content

Instantly share code, notes, and snippets.

@AllardQuek
Created July 2, 2021 09:42
Show Gist options
  • Save AllardQuek/9ac05cfb158e9bfd796e9e61557ac710 to your computer and use it in GitHub Desktop.
Save AllardQuek/9ac05cfb158e9bfd796e9e61557ac710 to your computer and use it in GitHub Desktop.
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