Custom file input

This addon ships with a pre-wired <FileInput /> component, but you can always bring your own file input.

Here's how to use a native file input.

import { useState } from "react";
import { useS3Upload } from "next-s3-upload";

export default function UploadPage() {
  let [imageUrl, setImageUrl] = useState();
  let { uploadToS3 } = useS3Upload();

  let handleFileChange = async event => {
    let file = event.target.files[0];
    let { url } = await uploadToS3(file);

    setImageUrl(url);
  };

  return (
    <div>
      <input type="file" onChange={handleFileChange} />

      {imageUrl && <img src={imageUrl} />}
    </div>
  );
}