CldUploadWidget version problem with onUpload #582
Unanswered
heidebloem
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I need to update some old code to the newer version of Cloudinary, using CldUploadWidget.
The previous 'onUpload' is depreciated, so in my code, I replaced it with the newer 'onSuccess'. But my code still does not work when running. Anyone knows what more I should change? Here is my code (see the return part):
"use client";
import { CldUploadWidget } from "next-cloudinary";
//import { CldImage } from "next-cloudinary";
import Image from "next/image";
import { useCallback } from "react";
import { MdAddAPhoto } from "react-icons/md";
//import { useState } from "react";
declare global {
var cloudinary: any;
}
interface ImageUploadProps {
onChange: (value: string) => void;
value: string;
}
const ImageUpload: React.FC = ({ onChange, value }) => {
const handleUpload = useCallback(
(result: any) => onChange(result.info.secure_url),
[onChange]
);
return (
<CldUploadWidget
onSuccess={handleUpload}//replaces the previous onUpload
//onUpload = {handleUpload}
uploadPreset="mkqqszfh"
options={{
maxFiles: 1,
}}
>
{({ open }) => {
return (
<div
onClick={() => open?.()}
className="
relative
cursor-pointer
hover:opacity-70
transition border-dashed
border-2 p-20 border-neutral-300
flex flex-col
justify-center
items-center
gap-4
text-neutral-600"
>
{value && (
<Image
alt="Upload"
fill
style={{ objectFit: "cover" }}
src={value}
/>
)}
);
}}
);
};
export default ImageUpload;
Thanks a lot.
Beta Was this translation helpful? Give feedback.
All reactions