import Uploady, { useUploady, useRequestPreSend, UPLOADER_EVENTS } from "@rpldy/uploady"; import { asUploadButton } from "@rpldy/upload-button"; import Button from "src/Components/Button/Button"; import { fetchUploadUrl } from "./fetch-upload-img-url"; import ImagePreviews from "./ImagePreviews"; import { FaImage } from "react-icons/fa"; import UploadDropZone from "@rpldy/upload-drop-zone"; import { forwardRef, useCallback } from "react"; import styles from './styles.module.scss' import { MdFileUpload } from "react-icons/md"; import { AiOutlineCloudUpload } from "react-icons/ai"; import { motion } from "framer-motion"; interface Props { url: string; } const UploadBtn = asUploadButton((props: any) => { useRequestPreSend(async (data) => { const filename = data.items?.[0].file.name ?? '' const url = await fetchUploadUrl({ filename }); return { options: { destination: { url } } } }) // const handleClick = async () => { // // Make a request to get the url // try { // var bodyFormData = new FormData(); // bodyFormData.append('requireSignedURLs', "false"); // const res = await axios({ // url: 'https://cors-anywhere.herokuapp.com/https://api.cloudflare.com/client/v4/accounts/783da4f06e5fdb9012c0632959a6f5b3/images/v2/direct_upload', // method: 'POST', // data: bodyFormData, // headers: { // "Authorization": "Bearer Xx2-CdsTliYkq6Ayz-1GX4CZubdQVxMwOSDbajP0", // } // }) // uploady.upload(res.data.result.uploadUrl, { // destination: res.data.result.uploadUrl // }) // } catch (error) { // console.log(error); // } // // make the request with the files // // uploady.upload() // } return Upload Image }); const DropZone = forwardRef((props, ref) => { const { onClick, ...buttonProps } = props; useRequestPreSend(async (data) => { const filename = data.items?.[0].file.name ?? '' const url = await fetchUploadUrl({ filename }); return { options: { destination: { url } } } }) const onZoneClick = useCallback( (e: any) => { if (onClick) { onClick(e); } }, [onClick] ); return Drop your files here or click to browse Drop it to upload }) const DropZoneButton = asUploadButton(DropZone); export default function FileUploadInput(props: Props) { return ( { const { id, filename, variants } = item?.uploadResponse?.data?.result ?? {} if (id) { console.log(id, filename, variants); } } }} > {/* */} ) }