gpt4 book ai didi

reactjs - React 中 Cloudinary 小部件的使用

转载 作者:行者123 更新时间:2023-12-03 13:42:16 24 4
gpt4 key购买 nike

我是 React 新手。我正在寻找一种将照片上传到 Cloudinary 的好方法。我看到了 Cloudinary 小部件,但我在 React 应用程序中实现它时遇到了困难,如下所述: https://cloudinary.com/blog/how_to_build_an_image_library_with_react_cloudinary#uploading_images

我将脚本标签放在index.html正文中:

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

然后尝试在组件中使用:

class Landing extends Component {
uploadWidget() {
cloudinary.openUploadWidget(
{ cloud_name: 'minetoo', upload_preset: 'mine', tags: ['xmas'] },
function(error, result) {
console.log(result);
}
);
}
...

但我收到错误:“cloudinary”未定义

如果重要的话,我的应用程序的样板是使用 create-react-app 生成的。

最佳答案

正如所指出的那样,这是非常正常的 herehere 。您需要从 window 对象访问 cloudinary 对象:

window.cloudinary.openUploadWidget(...)

关于reactjs - React 中 Cloudinary 小部件的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47287916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com