Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createUploadWidget #561

Open
zhen1asemen1uk opened this issue Apr 14, 2023 · 10 comments
Open

createUploadWidget #561

zhen1asemen1uk opened this issue Apr 14, 2023 · 10 comments

Comments

@zhen1asemen1uk
Copy link

What about "createUploadWidget" in "cloudinary" types?

@tamaracloudinary
Copy link

tamaracloudinary commented Apr 16, 2023

Hi there @zhen1asemen1uk,
Can you please elaborate on what you think is missing? createUploadWidget is a method, not a type. We have a working example in our docs you can check out here, and you can read more on our JS SDK here:
https://cloudinary.com/documentation/javascript_image_and_video_upload

@zhen1asemen1uk
Copy link
Author

Yes, it's a method, but it is not described in types, and my typescript says createUploadWidget not assigning to cloudinary

@skalahasti-cloudinary
Copy link

Hi @zhen1asemen1uk ,

Can you please provide us your sample code here or you can create a support ticket at:
https://support.cloudinary.com/hc/en-us/requests/new.

Thanks
Sree

@zhen1asemen1uk
Copy link
Author

zhen1asemen1uk commented Apr 20, 2023

`
import React, { useRef } from "react";
import { Script } from "gatsby";
import { Cloudinary } from "@cloudinary/url-gen";

interface IUploadWidget {
children: (props: { open: () => void }) => React.ReactElement;
onUpload: (error: any, result: any, widget?: any) => void; // Use 'any' for widget type
}

const UploadWidget: React.FC = ({ children, onUpload }) => {
const cloudinary = useRef<Cloudinary | null>(null);
const widget = useRef<any | null>(null); // Use 'any' for widget type

const createWidget = () => {
	const options = {
		cloudName: process.env.GATSBY_CLOUD_NAME,
		uploadPreset: process.env.GATSBY_UPLOAD_PRESET,
		folder: "qr-codes",
	};

	return cloudinary.current?.createUploadWidget( // 👈🏻 here error
		options,
		(error: any, result: any) => {
			if (error || result.event === "success") {
				onUpload(error, result);
			}
		}
	);
};

const open = () => {
	if (!widget?.current) {
		widget.current = createWidget();
	}

	widget?.current && widget.current.open();
};

const handleOnLoad = () => {
	cloudinary.current = window?.cloudinary;
};

return (
	<>
		{children({ open })}
		<Script
			id='cloudinary'
			src='https://widget.cloudinary.com/v2.0/global/all.js'
			onLoad={handleOnLoad}
		/>
	</>
);

};

export default UploadWidget;
`

@tamaracloudinary
Copy link

Hi there @zhen1asemen1uk, I couldn't replicate the issue. Do you still get that error?
Can you please copy the full error message you get? and tell us your cloud name? any info will help here.
If you don't want to share these details publicly, please open a new Support ticket.
Thanks,
Tamara

@zhen1asemen1uk
Copy link
Author

I can provide a screenshot code and error. It's a problem with types. Try past my provide code and u will see the same

Error: "Property 'createUploadWidget' does not exist on type 'Cloudinary'.ts(2339)"

Screenshot 2023-04-24 at 13 12 24

@zhen1asemen1uk
Copy link
Author

See type createUploadWidget in node_modules Cloudinary ??

Screenshot 2023-04-24 at 13 16 56

@ecpa-cldtools
Copy link

Hi @zhen1asemen1uk The Upload Widget javascript package can be loaded from:

<script src="https://upload-widget.cloudinary.com/global/all.js" type="text/javascript">  
</script>

See https://cloudinary.com/documentation/upload_widget#how_to_set_up_and_integrate_the_upload_widget_into_your_site_or_app

Could you help to add this to your web app and see if it helps to resolve the issue?

@zhen1asemen1uk
Copy link
Author

The same error. This script doesn't add any types to my project.

@ecpa-cldtools
Copy link

Additionally, as you are calling the JavaScript on your typescript component - you may need to allow the loading of the javascript as described in this documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants