如何在上传时获取cloudinary小部件图像信息? [英] How to get the cloudinary widget image info on upload?

查看:61
本文介绍了如何在上传时获取cloudinary小部件图像信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cloudinary小部件在我的网站上上传图片。现在,我想从图片上传时获取信息,例如

I'm using the cloudinary widget to upload images on my websites. Now I'd like to get the info from an image when it's being uploaded e.g. the path of that image.

我可以看到在上传图像时控制台日志中提供了此信息,例如{path: v1586568667 / myusername / lp62llmn8sa7r5vqjovd.jpg}

I can see that this information is available in the console log when uploading the image e.g. {path: "v1586568667/myusername/lp62llmn8sa7r5vqjovd.jpg"}

我相信我必须使用Ajax来获取此信息,但我正努力寻找一些示例,

I believe I have to use ajax to get this information, but I'm struggling to find some examples, if someone could point me to the right direction.

推荐答案

感谢大家的反馈。我找到了一种适合我需要的方法,请参见下面的更新脚本,在该脚本中,我使用 var imagePath获取 result.info.path值,然后可以在页面上的任何位置使用 document.getElementById调用它例如,

Thanks everyone for your feedback. I've found a way that suit my needs, see updated script below where I grab the "result.info.path" value with "var imagePath", then I can call it anywhere I want on the page with "document.getElementById" for example.

var myWidget = cloudinary.createUploadWidget({
  cloudName: 'myusername', 
  uploadPreset: 'preset_unsigned'}, (error, result) => { 
    if (!error && result && result.event === "success") { 
      console.log('Done! Here is the image info: ', result.info); 

    var imagePath = result.info.path;

        document.getElementById("uploadedImage").src = "https://res.cloudinary.com/myusername/image/upload/" + imagePath;

    }
  }
)

document.getElementById("upload_widget").addEventListener("click", function(){
    myWidget.open();
  }, false);

这篇关于如何在上传时获取cloudinary小部件图像信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆