我正在使用 cloudinary 小部件在我的网站上上传图像。现在我想在上传图像时从图像中获取信息,例如该图像的路径。
我可以看到上传图像时控制台日志中提供了此信息,例如{路径:“v1586568667/myusername/lp62llmn8sa7r5vqjovd.jpg”}
我相信我必须使用ajax来获取这些信息,但我正在努力寻找一些例子,如果有人能指出我正确的方向。
最佳答案
感谢大家的反馈。我找到了一种适合我需要的方法,请参阅下面更新的脚本,其中我使用“var imagePath”获取“result.info.path”值,然后我可以使用“document.getElementById”在页面上的任何位置调用它例如。
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);
关于javascript - 如何获取上传的cloudinary小部件图像信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61153317/