import React, { useState } from "react";
import "./image.css";
function Image() {
const [image, setImage] = useState("");
const [imageUrl, setImageUrl] = useState("");
const postDetails = async () => {
const data = new FormData();
data.append("file", image);
data.append("upload_preset", "harmony");
data.append("cloud_name", "mattglwilliams");
const settings = { method: "POST", body: data };
try {
const fetchData = await fetch(
"https://api.cloudinary.com/v1_1/mattglwilliams/image/upload",
settings
);
const resData = await fetchData.json();
console.log(resData.url);
if (resData) {
setImageUrl(resData.url);
console.log("imageUrl", imageUrl);
}
} catch (e) {
console.log(e);
}
};
return (
<>
Uplaod Image
setImage(e.target.files[0])} />
>
);
}
export default Image;