Skip to content

Instantly share code, notes, and snippets.

@Josh4324
Created October 31, 2022 21:33
Show Gist options
  • Save Josh4324/20808688ce0bd8652c9927a4f399deaa to your computer and use it in GitHub Desktop.
Save Josh4324/20808688ce0bd8652c9927a4f399deaa to your computer and use it in GitHub Desktop.
index.js
import Head from "next/head";
import styles from "../styles/Home.module.css";
import Sidebar from "../components/Sidebar";
export default function Home() {
//The showWidget pops up a cloudinary widget that we can use to upload any file and it returns an object that contains
// the name, link to the url of the uploaded file and other information
const showWidget = () => {
const myWidget = window.cloudinary.createUploadWidget(
{
cloudName: "Insert your cloudName",
uploadPreset: "Insert your uploadPreset",
},
(error, result) => {
if (!error && result && result.event === "success") {
console.log(result);
}
}
);
myWidget.open();
};
return (
<div>
<Head>
<title>CloudDrop - Home</title>
<meta name="description" content="Clouddrop" />
{/* eslint-disable-next-line @next/next/no-sync-scripts */}
<script
src="https://upload-widget.cloudinary.com/global/all.js"
type="text/javascript"
></script>
</Head>
<div className={styles.homeflex}>
<Sidebar />
<div className={styles.home}>
<div className={styles.cloud}>
<h1 className={styles.homehead}>CloudDrop </h1>
<h3 className={styles.homehead2}></h3>
</div>
{/* We added the showWidget function to the onClick handler */}
<button onClick={showWidget} type="button" className={styles.upload}>
Upload File
</button>
</div>
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment